Skip to content

Commit

Permalink
Case insensitivity option for #find_entry
Browse files Browse the repository at this point in the history
  • Loading branch information
kinkou committed Feb 19, 2015
1 parent 0cbae14 commit 61a4435
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/zip/entry_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def include?(entry)
@entry_set.include?(to_key(entry))
end

def find_entry(entry)
@entry_set[to_key(entry)]
def find_entry(entry, case_sensitively = true)
return @entry_set[to_key(entry)] if case_sensitively
entry = @entry_set.find { |k, _| k.downcase == to_key(entry).downcase }
entry.last if entry
end

def <<(entry)
Expand Down
6 changes: 6 additions & 0 deletions test/entry_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def test_entries
assert_equal(ZIP_ENTRIES, @zipEntrySet.entries)
end

def test_find_entry
# by default, #find_entry is case-sensitive
assert_equal(ZIP_ENTRIES[0], @zipEntrySet.find_entry('name1'))
assert_equal(ZIP_ENTRIES[0], @zipEntrySet.find_entry('NaMe1', false))
end

def test_entries_with_sort
::Zip.sort_entries = true
assert_equal(ZIP_ENTRIES.sort, @zipEntrySet.entries)
Expand Down

0 comments on commit 61a4435

Please sign in to comment.