module StateGeoTools

Because I got sick of copying and pasting arrays of states everywhere, this utility provides some convenience methods to get a full set of US states and territories. It also includes a pair of convenience methods.

The utility modules are all public, in the event that one should need to use them in a slightly different way, but the common use case is in this.

See the README for examples.

Constants

VERSION

Public Class Methods

count_states_in(string) click to toggle source

Count instances of states in a string.

# File lib/state_geo_tools.rb, line 52
def self.count_states_in(string)
  count_instances string, States::STATES
end
count_territories_in(string) click to toggle source

Count instances of territories passed in a string.

# File lib/state_geo_tools.rb, line 57
def self.count_territories_in(string)
  count_instances string, Territories::TERRITORIES
end
state_codes(topload: nil) click to toggle source

Return an array of two-letter state codes, and DC. Optionally pull items up top with a topload array kwarg.

# File lib/state_geo_tools.rb, line 29
def self.state_codes(topload: nil)
  return topload_items(States::STATE_CODES, topload) if topload

  States::STATE_CODES
end
states(topload: nil) click to toggle source

Return an array of states and the District of Columbia. Optionally pull items up top with a topload array kwarg.

# File lib/state_geo_tools.rb, line 21
def self.states(topload: nil)
  return topload_items(States::STATES, topload) if topload

  States::STATES
end
territories(topload: nil) click to toggle source

Return an array of US territories. Optionally pull items up top with a topload array kwarg.

# File lib/state_geo_tools.rb, line 37
def self.territories(topload: nil)
  return topload_items(Territories::TERRITORIES, topload) if topload

  Territories::TERRITORIES
end
territory_codes(topload: nil) click to toggle source

Return an array of two-letter US territory codes. Optionally pull items up top with a topload array kwarg.

# File lib/state_geo_tools.rb, line 45
def self.territory_codes(topload: nil)
  return topload_items(Territories::TERRITORY_CODES, topload) if topload

  Territories::TERRITORY_CODES
end