Case insensitivity option for #find_entry
This commit is contained in:
parent
0cbae14c76
commit
61a4435cc3
|
@ -13,8 +13,10 @@ module Zip
|
||||||
@entry_set.include?(to_key(entry))
|
@entry_set.include?(to_key(entry))
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_entry(entry)
|
def find_entry(entry, case_sensitively = true)
|
||||||
@entry_set[to_key(entry)]
|
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
|
end
|
||||||
|
|
||||||
def <<(entry)
|
def <<(entry)
|
||||||
|
|
|
@ -65,6 +65,12 @@ class ZipEntrySetTest < MiniTest::Test
|
||||||
assert_equal(ZIP_ENTRIES, @zipEntrySet.entries)
|
assert_equal(ZIP_ENTRIES, @zipEntrySet.entries)
|
||||||
end
|
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
|
def test_entries_with_sort
|
||||||
::Zip.sort_entries = true
|
::Zip.sort_entries = true
|
||||||
assert_equal(ZIP_ENTRIES.sort, @zipEntrySet.entries)
|
assert_equal(ZIP_ENTRIES.sort, @zipEntrySet.entries)
|
||||||
|
|
Loading…
Reference in New Issue