Module: StateGeoTools

Extended by:
Toploader
Defined in:
lib/state_geo_tools.rb,
lib/state_geo_tools/version.rb,
lib/state_geo_tools/toploader.rb,
lib/state_geo_tools/state_constants.rb,
lib/state_geo_tools/territory_constants.rb

Overview

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.

Defined Under Namespace

Modules: States, Territories, Toploader

Constant Summary collapse

VERSION =
'1.0.0'

Constants included from Toploader

Toploader::TOPLOAD_ERROR

Class Method Summary collapse

Methods included from Toploader

topload_items

Class Method Details

.count_states_in(string) ⇒ Object

Count instances of states in a string.



52
53
54
# File 'lib/state_geo_tools.rb', line 52

def self.count_states_in(string)
  count_instances string, States::STATES
end

.count_territories_in(string) ⇒ Object

Count instances of territories passed in a string.



57
58
59
# File 'lib/state_geo_tools.rb', line 57

def self.count_territories_in(string)
  count_instances string, Territories::TERRITORIES
end

.state_codes(topload: nil) ⇒ Object

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



29
30
31
32
33
# 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) ⇒ Object

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



21
22
23
24
25
# 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) ⇒ Object

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



37
38
39
40
41
# 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) ⇒ Object

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



45
46
47
48
49
# 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