module Geolookup::USA::State

Constants

DOMESTIC_STATE_CUTOFF
STATE_ABBREVIATION_TO_NAME_FILE
STATE_CODE_TO_ABBREVIATION_FILE
STATE_CODE_TO_FULL_FILE
STATE_LAT_LONG_FILE
STATE_NAME_TO_CODE_FILE
TERRITORY_STATES_FILE

Public Class Methods

abbreviation_to_code(state_name)
Alias for: name_to_code
abbreviation_to_lat_long(name)
Alias for: name_to_lat_long
abbreviation_to_name(state_abbrev) click to toggle source

self.state_abbreviation_to_full_name

Given a state abbreviation return the full state name

# File lib/geolookup/usa/state.rb, line 67
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() click to toggle source

self.abbreviations

Returns an array of state abbreviations

# File lib/geolookup/usa/state.rb, line 96
def self.abbreviations
  @state_code_to_abbreviation ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE)
  @state_code_to_abbreviation.values
end
abbreviations_and_names() click to toggle source

self.abbreviations_and_names

Returns a hash of abbreviations and state names

# File lib/geolookup/usa/state.rb, line 145
def self.abbreviations_and_names
  @state_abbreviation_to_name ||= Geolookup.load_hash_from_file(STATE_ABBREVIATION_TO_NAME_FILE)
end
code_to_abbreviation(state_code) click to toggle source

self.code_to_state_abbreviation

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

# File lib/geolookup/usa/state.rb, line 36
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) click to toggle source

self.code_to_lat_long

Given a code return the lat and long

# File lib/geolookup/usa/state.rb, line 86
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) click to toggle source

self.code_to_name

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

# File lib/geolookup/usa/state.rb, line 26
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() click to toggle source

self.codes

Returns an array of state names

# File lib/geolookup/usa/state.rb, line 164
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_abbreviations() click to toggle source

self.codes_and_abbreviations

Returns a hash of state_codes and abbreviations

# File lib/geolookup/usa/state.rb, line 136
def self.codes_and_abbreviations
  @codes_and_abbreviations ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE)
end
codes_and_names() click to toggle source

self.codes_and_names

Returns a hash of state_codes and names

# File lib/geolookup/usa/state.rb, line 127
def self.codes_and_names
  @codes_and_names ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
end
domestic_abbreviations() click to toggle source

self.abbreviations

Returns an array of state abbreviations

# File lib/geolookup/usa/state.rb, line 106
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_names() click to toggle source

self.domestic_names

Returns an array of domestic state names

# File lib/geolookup/usa/state.rb, line 117
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
ignored?(state) click to toggle source
# File lib/geolookup/usa/state.rb, line 208
def self.ignored?(state) territory?(state) end
ignored_state_codes() click to toggle source
# File lib/geolookup/usa/state.rb, line 206
def self.ignored_state_codes() territory_state_codes end
ignored_state_names() click to toggle source
# File lib/geolookup/usa/state.rb, line 207
def self.ignored_state_names() territory_state_names end
name_to_abbreviation(state_abbrev) click to toggle source

self.name_to_abbreviation

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

# File lib/geolookup/usa/state.rb, line 47
def self.name_to_abbreviation(state_abbrev)
  code_to_abbreviation(abbreviation_to_code(state_abbrev))
end
name_to_code(state_name) click to toggle source

self.state_name_to_code

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

# File lib/geolookup/usa/state.rb, line 57
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
Also aliased as: abbreviation_to_code
name_to_lat_long(name) click to toggle source

self.name_to_lat_long

Given a state name return the lat and long

# File lib/geolookup/usa/state.rb, line 77
def self.name_to_lat_long(name)
  code_to_lat_long(name_to_code(name.to_s.upcase))
end
Also aliased as: abbreviation_to_lat_long
names() click to toggle source

self.names

Returns an array of state names

# File lib/geolookup/usa/state.rb, line 154
def self.names
  @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
  @state_code_to_full.values
end
territory?(state) click to toggle source

self.territory?

Given a state name, abbreviation, or code, returns true if the state should be territory and false otherwise.

# File lib/geolookup/usa/state.rb, line 195
def self.territory?(state)
  @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE)
  titlized_state_name = state.to_s.split.map(&:capitalize).join(' ')

  is_territory_state_name = territory_state_names.include? titlized_state_name
  is_territory_state_code = territory_state_codes.include? state.to_i
  is_territory_state_abbreviation = territory_state_names.include? abbreviation_to_name(state)

  is_territory_state_name || is_territory_state_code || is_territory_state_abbreviation
end
territory_state_codes() click to toggle source

self.territory_state_codes

Returns an array of territory state codes

# File lib/geolookup/usa/state.rb, line 174
def self.territory_state_codes
  @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE)
  @territory_states.keys
end
territory_state_names() click to toggle source

self.territory_state_names

Returns an array of territory state names

# File lib/geolookup/usa/state.rb, line 184
def self.territory_state_names
  @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE)
  @territory_states.values
end