lib/geolookup/usa/state.rb in geolookup-0.6.2 vs lib/geolookup/usa/state.rb in geolookup-0.6.4

- old
+ new

@@ -5,19 +5,19 @@ 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' - IGNORED_STATES_FILE = 'IGNORED_STATES.yml' + TERRITORY_STATES_FILE = 'TERRITORY_STATES.yml' DOMESTIC_STATE_CUTOFF = 56 @state_code_to_full @state_code_to_abbreviation @state_name_to_code @state_abbreviation_to_name @state_lat_long - @ignored_states + @territory_states @domestic_state_code_to_name @domestic_state_code_to_abbreviation ################################################################### # self.code_to_name # @@ -165,27 +165,48 @@ @state_code_to_full ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE) @state_code_to_full.keys end ################################################################### - # self.ignored_state_codes + # self.territory_state_codes # - # Returns an array of ignored state codes + # Returns an array of territory state codes # - def self.ignored_state_codes - @ignored_states ||= Geolookup.load_hash_from_file(IGNORED_STATES_FILE) - @ignored_states.keys + def self.territory_state_codes + @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE) + @territory_states.keys end ################################################################### - # self.ignored_state_names + # self.territory_state_names # - # Returns an array of ignored state names + # Returns an array of territory state names # - def self.ignored_state_names - @ignored_states ||= Geolookup.load_hash_from_file(IGNORED_STATES_FILE) - @ignored_states.values + def self.territory_state_names + @territory_states ||= Geolookup.load_hash_from_file(TERRITORY_STATES_FILE) + @territory_states.values end + + ################################################################### + # self.territory? + # + # Given a state name, abbreviation, or code, returns true if the + # state should be territory and false otherwise. + # + 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 + + def self.ignored_state_codes() territory_state_codes end + def self.ignored_state_names() territory_state_names end + def self.ignored?(state) territory?(state) end class << self alias :abbreviation_to_code :name_to_code alias :abbreviation_to_lat_long :name_to_lat_long end