Module: Geolookup::USA::State

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

Constant Summary collapse

STATE_CODE_TO_FULL_FILE =
'STATE_CODE_TO_FULL.yml'
STATE_CODE_TO_ABBREVIATION_FILE =
'STATE_CODE_TO_STATE.yml'
STATE_NAME_TO_CODE_FILE =
'STATE_NAME_TO_CODE.yml'
STATE_ABBREVIATION_TO_NAME_FILE =
'STATE_FULL_STATE_NAMES.yml'
STATE_LAT_LONG_FILE =
'STATE_LAT_LONG.yml'
DOMESTIC_STATE_CUTOFF =
56

Class Method Summary collapse

Class Method Details

.abbreviation_to_name(state_abbrev) ⇒ Object

self.state_abbreviation_to_full_name

Given a state abbreviation return the full state name



65
66
67
68
# File 'lib/geolookup/usa/state.rb', line 65

def self.abbreviation_to_name(state_abbrev)
  @state_abbreviation_to_name ||= Geolookup.load_hash_from_file(STATE_ABBREVIATION_TO_NAME_FILE)
  @state_abbreviation_to_name[state_abbrev.to_s.upcase]
end

.abbreviationsObject

self.abbreviations

Returns an array of state abbreviations



94
95
96
97
# File 'lib/geolookup/usa/state.rb', line 94

def self.abbreviations
  @state_code_to_abbreviation ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE)
  @state_code_to_abbreviation.values
end

.code_to_abbreviation(state_code) ⇒ Object

self.code_to_state_abbreviation

Given a state code output the state abbreviation. Else return nil



34
35
36
37
# File 'lib/geolookup/usa/state.rb', line 34

def self.code_to_abbreviation(state_code)
  @state_code_to_abbreviation ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE)
  @state_code_to_abbreviation[state_code.to_s.to_i]
end

.code_to_lat_long(state_code) ⇒ Object

self.code_to_lat_long

Given a code return the lat and long



84
85
86
87
# File 'lib/geolookup/usa/state.rb', line 84

def self.code_to_lat_long(state_code)
  @state_lat_long ||= Geolookup.load_hash_from_file(STATE_LAT_LONG_FILE)
  @state_lat_long[state_code.to_s.to_i]
end

.code_to_name(state_code) ⇒ Object

self.code_to_name

Given a state code output full state name. Else return nil



24
25
26
27
# File 'lib/geolookup/usa/state.rb', line 24

def self.code_to_name(state_code)
  @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
  @state_code_to_full[state_code.to_s.to_i]
end

.codesObject

self.codes

Returns an array of state names



153
154
155
156
# File 'lib/geolookup/usa/state.rb', line 153

def self.codes
  @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
  @state_code_to_full.keys
end

.codes_and_abbreviationsObject

self.names

Returns an array of state names



134
135
136
# File 'lib/geolookup/usa/state.rb', line 134

def self.codes_and_abbreviations
  @codes_and_abbreviations ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE)
end

.codes_and_namesObject

self.names

Returns an array of state names



125
126
127
# File 'lib/geolookup/usa/state.rb', line 125

def self.codes_and_names
  @codes_and_names ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
end

.domestic_abbreviationsObject

self.abbreviations

Returns an array of state abbreviations



104
105
106
107
# File 'lib/geolookup/usa/state.rb', line 104

def self.domestic_abbreviations
  @domestic_state_code_to_abbreviation ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE).delete_if{|code, abbr| code > DOMESTIC_STATE_CUTOFF}
  @domestic_state_code_to_abbreviation.values
end

.domestic_namesObject

self.domestic_names

Returns an array of domestic state names



115
116
117
118
# File 'lib/geolookup/usa/state.rb', line 115

def self.domestic_names
 @domestic_state_code_to_name ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE).delete_if{|code, abbr| code > DOMESTIC_STATE_CUTOFF}
  @domestic_state_code_to_name.values
end

.name_to_abbreviation(state_abbrev) ⇒ Object

self.name_to_abbreviation

Given a state name OR abbreviation return a code. It takes both an abbreviation and a state full name



45
46
47
# File 'lib/geolookup/usa/state.rb', line 45

def self.name_to_abbreviation(state_abbrev)
  code_to_abbreviation(abbreviation_to_code(state_abbrev))
end

.name_to_code(state_name) ⇒ Object Also known as: abbreviation_to_code

self.state_name_to_code

Given a state name OR abbreviation return a code. It takes both an abbreviation and a state full name



55
56
57
58
# File 'lib/geolookup/usa/state.rb', line 55

def self.name_to_code(state_name)
  @state_name_to_code ||= Geolookup.load_hash_from_file(STATE_NAME_TO_CODE_FILE)
  @state_name_to_code[state_name.to_s.upcase]
end

.name_to_lat_long(name) ⇒ Object Also known as: abbreviation_to_lat_long

self.name_to_lat_long

Given a state name return the lat and long



75
76
77
# File 'lib/geolookup/usa/state.rb', line 75

def self.name_to_lat_long(name)
  code_to_lat_long(name_to_code(name.to_s.upcase))
end

.namesObject

self.names

Returns an array of state names



143
144
145
146
# File 'lib/geolookup/usa/state.rb', line 143

def self.names
  @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
  @state_code_to_full.values
end