Class: Geet::Utils::StringMatchingSelection

Inherits:
Object
  • Object
show all
Defined in:
lib/geet/utils/string_matching_selection.rb

Instance Method Summary collapse

Instance Method Details

#select_entries(entry_type, entries, raw_patterns, name_method: nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/geet/utils/string_matching_selection.rb', line 22

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



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/geet/utils/string_matching_selection.rb', line 6

def select_entry(entry_type, entries, pattern, name_method: nil)
  entries_found = entries.select do |entry|
    entry = entry.send(name_method) if name_method
    entry.downcase == pattern.downcase
  end

  case entries_found.size
  when 1
    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