Class: Geet::Utils::StringMatchingSelection
- Inherits:
-
Object
- Object
- Geet::Utils::StringMatchingSelection
- Extended by:
- T::Sig
- Defined in:
- lib/geet/utils/string_matching_selection.rb
Instance Method Summary collapse
- #select_entries(entry_type, entries, raw_patterns, name_method: nil) ⇒ Object
- #select_entry(entry_type, entries, pattern, name_method: nil) ⇒ Object
Instance Method Details
#select_entries(entry_type, entries, raw_patterns, name_method: nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/geet/utils/string_matching_selection.rb', line 43 def select_entries(entry_type, entries, raw_patterns, name_method: nil) patterns = raw_patterns.split(",") patterns.map do |pattern| # Haha. select_entry(entry_type, entries, pattern, name_method: name_method) end end |
#select_entry(entry_type, entries, pattern, name_method: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/geet/utils/string_matching_selection.rb', line 18 def select_entry(entry_type, entries, pattern, name_method: nil) entries_found = entries.select do |entry| compared_entry = name_method ? T.unsafe(entry).send(name_method) : entry T.unsafe(compared_entry).downcase == pattern.downcase end case entries_found.size when 1 T.must(entries_found.first) when 0 raise "No entry found for #{entry_type} pattern: #{pattern.inspect}" else raise "Multiple entries found for #{entry_type} pattern #{pattern.inspect}: #{entries_found}" end end |