Module: Geolookup::USA::County

Defined in:
lib/geolookup/usa/county.rb

Constant Summary collapse

COUNTY_CODE_TO_NAME_FILE =
'./lib/data/COUNTY_CODE_TO_NAME.yml'
COUNTY_NAME_TO_CODE_FILE =
'./lib/data/COUNTY_NAME_TO_CODE.yml'
COUNTY_LAT_LONG_FILE =
'./lib/data/COUNTY_LAT_LONG.yml'

Class Method Summary collapse

Class Method Details

.code_to_lat_long(state_code, county_code) ⇒ Object

self.code_to_lat_long

Given a state and county code output county latitude longitude. Else return nil



48
49
50
51
52
53
# File 'lib/geolookup/usa/county.rb', line 48

def self.code_to_lat_long(state_code, county_code)
  @county_lat_long ||= Geolookup.load_hash_from_file(COUNTY_LAT_LONG_FILE)
  return nil unless @county_lat_long[state_code.to_s.to_i]

  @county_lat_long[state_code.to_s.to_i][county_code.to_s.to_i]
end

.code_to_name(state_code, county_code) ⇒ Object

self.code_to_name

Given a state and county code output the county name Else return nil

EX: code_to_name(1, 1) => “AUTAUGA”



20
21
22
23
24
25
# File 'lib/geolookup/usa/county.rb', line 20

def self.code_to_name(state_code, county_code) 
  @county_code_to_name ||= Geolookup.load_hash_from_file(COUNTY_CODE_TO_NAME_FILE)
  return nil unless @county_code_to_name[state_code.to_s.to_i]
        
  @county_code_to_name[state_code.to_s.to_i][county_code.to_s.to_i]
end

.name_to_code(state_code, county_name) ⇒ Object

self.name_to_code

Given a state and county name output the county code Else return nil

EX: name_to_code(1, ‘baldwin’) => => {“AUTAUGA” => 1, “BALDWIN” => 3, .…}



35
36
37
38
39
40
# File 'lib/geolookup/usa/county.rb', line 35

def self.name_to_code(state_code, county_name)
  @county_name_to_code ||= Geolookup.load_hash_from_file(COUNTY_NAME_TO_CODE_FILE)
  return nil unless @county_name_to_code[state_code.to_s.to_i]

  @county_name_to_code[state_code.to_s.to_i][county_name.to_s.upcase]
end