Class: Geomash::TownLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/geomash/town_lookup.rb

Class Method Summary collapse

Class Method Details

.state_town_lookup(state_key, string) ⇒ Object

Only returns one result for now… Need to avoid cases like “Boston” and “East Boston”



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/geomash/town_lookup.rb', line 5

def self.state_town_lookup(state_key, string)
  return_tgn_id = nil
  matched_terms_count = 0
  matching_towns = Geomash::Constants::STATE_TOWN_TGN_IDS[state_key.to_sym].select {|hash| string.include?(hash[:location_name])}
  matching_towns.each do |matching_town|
    if matching_town[:location_name].split(' ').length > matched_terms_count
      return_tgn_id = matching_town[:tgn_id]
      matched_terms_count = matching_town[:location_name].split(' ').length
    end
  end

  return return_tgn_id
end