Module: Geolookup::USA::State
- Defined in:
- lib/geolookup/usa/state.rb
Constant Summary collapse
- STATE_CODE_TO_FULL_FILE =
'./lib/data/STATE_CODE_TO_FULL.yml'- STATE_CODE_TO_ABBREVIATION_FILE =
'./lib/data/STATE_CODE_TO_STATE.yml'- STATE_NAME_TO_CODE_FILE =
'./lib/data/STATE_NAME_TO_CODE.yml'- STATE_ABBREVIATION_TO_NAME_FILE =
'./lib/data/STATE_FULL_STATE_NAMES.yml'- STATE_LAT_LONG_FILE =
'./lib/data/STATE_LAT_LONG.yml'
Class Method Summary collapse
-
.abbreviation_to_name(state_abbrev) ⇒ Object
self.state_abbreviation_to_full_name.
-
.abbreviations ⇒ Object
self.abbreviations.
-
.code_to_abbreviation(state_code) ⇒ Object
self.code_to_state_abbreviation.
-
.code_to_lat_long(state_code) ⇒ Object
self.code_to_lat_long.
-
.code_to_name(state_code) ⇒ Object
self.code_to_name.
-
.codes ⇒ Object
self.codes.
-
.name_to_abbreviation(state_abbrev) ⇒ Object
self.name_to_abbreviation.
-
.name_to_code(state_name) ⇒ Object
(also: abbreviation_to_code)
self.state_name_to_code.
-
.name_to_lat_long(name) ⇒ Object
(also: abbreviation_to_lat_long)
self.name_to_lat_long.
-
.names ⇒ Object
self.names.
Class Method Details
.abbreviation_to_name(state_abbrev) ⇒ Object
self.state_abbreviation_to_full_name
Given a state abbreviation return the full state name
62 63 64 65 |
# File 'lib/geolookup/usa/state.rb', line 62 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 |
.abbreviations ⇒ Object
self.abbreviations
Returns an array of state abbreviations
91 92 93 94 |
# File 'lib/geolookup/usa/state.rb', line 91 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
31 32 33 34 |
# File 'lib/geolookup/usa/state.rb', line 31 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
81 82 83 84 |
# File 'lib/geolookup/usa/state.rb', line 81 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
21 22 23 24 |
# File 'lib/geolookup/usa/state.rb', line 21 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 |
.codes ⇒ Object
self.codes
Returns an array of state names
112 113 114 115 |
# File 'lib/geolookup/usa/state.rb', line 112 def self.codes @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE) @state_code_to_full.keys 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
42 43 44 |
# File 'lib/geolookup/usa/state.rb', line 42 def self.name_to_abbreviation(state_abbrev) code_to_name(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
52 53 54 55 |
# File 'lib/geolookup/usa/state.rb', line 52 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
72 73 74 |
# File 'lib/geolookup/usa/state.rb', line 72 def self.name_to_lat_long(name) code_to_lat_long(name_to_code(name.to_s.upcase)) end |
.names ⇒ Object
self.names
Returns an array of state names
102 103 104 105 |
# File 'lib/geolookup/usa/state.rb', line 102 def self.names @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE) @state_code_to_full.values end |