Module: Wasserstand::Finders

Included in:
Level, Waterway
Defined in:
lib/wasserstand/finders.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/wasserstand/finders.rb', line 3

def [](name)
  return nil if name.to_s.empty?
  results = all.select{|named| UnicodeUtils.upcase(name) == named.name}

  case results.size
  when 0
    nil # loookup returns nil if not found. This is a lookup, not find_all.
  when 1
    results.first
  else
    raise AmbigousNameError.new "Name '#{name}' is not unique. Found #{results.size} results."
  end
end