lib/uncharted/country.rb in uncharted-0.0.11 vs lib/uncharted/country.rb in uncharted-0.0.12

- old
+ new

@@ -35,28 +35,33 @@ def self.find(objects) case objects when Array objects.collect {|c| data[c]} - when Country + when Country, nil objects else # code code = objects.to_s code.upcase! data[code] end end def self.find_by_name(name) + return nil if name.nil? || name == "" closest = [nil, 0] @data.each do |code, country| return country if country.name == name intersection = country.names & Country.split_name(name) size = intersection.size return country if size == country.names.size closest = [country, size] if closest.last < size end return closest.first + end + + def self.search(object) + find(object) || find_by_name(object) end def self.countries @data.values end \ No newline at end of file