module Geolookup::USA::County
Constants
- COUNTY_CODE_TO_NAME_FILE
- COUNTY_LAT_LONG_FILE
- COUNTY_NAME_TO_CODE_FILE
Public Class Methods
code_to_lat_long(state_code, county_code)
click to toggle source
self.code_to_lat_long
Given a state and county code output county latitude longitude. Else return nil
# File lib/geolookup/usa/county.rb, line 44 def self.code_to_lat_long(state_code, county_code) @county_lat_long ||= Geolookup.load_hash_from_file(COUNTY_LAT_LONG_FILE) get_value_from_hash(@county_lat_long, state_code.to_s.to_i, county_code.to_s.to_i) end
code_to_name(state_code, county_code)
click to toggle source
self.code_to_name
Given a state and county code output the county name Else return nil
EX: code_to_name
(1, 1) => “AUTAUGA”
# 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) get_value_from_hash(@county_code_to_name, state_code.to_s.to_i, county_code.to_s.to_i) end
name_to_code(state_code, county_name)
click to toggle source
self.name_to_code
Given a state and county name output the county code Else return nil
EX: name_to_code
(1, 'baldwin') => {1 => {“AUTAUGA” => 1, “BALDWIN” => 3, .…}}
# File lib/geolookup/usa/county.rb, line 33 def self.name_to_code(state_code, county_name) @county_name_to_code ||= Geolookup.load_hash_from_file(COUNTY_NAME_TO_CODE_FILE) get_value_from_hash(@county_name_to_code, state_code.to_s.to_i, county_name.to_s.upcase) end
Private Class Methods
get_value_from_hash(hash, key1, key2)
click to toggle source
self.get_value_from_hash
Helper function to reduce code repetition Given a hash and 2 keys returns the value at that hash Return nil if the either key is not in the hash
EX: get_value(@county_code_to_name, 1, 1) => “AUTAUGA”
# File lib/geolookup/usa/county.rb, line 57 def self.get_value_from_hash(hash, key1, key2) return nil unless hash[key1] hash[key1][key2] end