Class: DigitalOpera::States

Inherits:
Object show all
Defined in:
lib/digital_opera/states.rb

Constant Summary collapse

US_STATES =
[
  ['Alabama', 'AL'],
  ['Alaska', 'AK'],
  ['Arizona', 'AZ'],
  ['Arkansas', 'AR'],
  ['California', 'CA'],
  ['Colorado', 'CO'],
  ['Connecticut', 'CT'],
  ['Delaware', 'DE'],
  ['District of Columbia', 'DC'],
  ['Florida', 'FL'],
  ['Georgia', 'GA'],
  ['Hawaii', 'HI'],
  ['Idaho', 'ID'],
  ['Illinois', 'IL'],
  ['Indiana', 'IN'],
  ['Iowa', 'IA'],
  ['Kansas', 'KS'],
  ['Kentucky', 'KY'],
  ['Louisiana', 'LA'],
  ['Maine', 'ME'],
  ['Maryland', 'MD'],
  ['Massachusetts', 'MA'],
  ['Michigan', 'MI'],
  ['Minnesota', 'MN'],
  ['Mississippi', 'MS'],
  ['Missouri', 'MO'],
  ['Montana', 'MT'],
  ['Nebraska', 'NE'],
  ['Nevada', 'NV'],
  ['New Hampshire', 'NH'],
  ['New Jersey', 'NJ'],
  ['New Mexico', 'NM'],
  ['New York', 'NY'],
  ['North Carolina', 'NC'],
  ['North Dakota', 'ND'],
  ['Ohio', 'OH'],
  ['Oklahoma', 'OK'],
  ['Oregon', 'OR'],
  ['Pennsylvania', 'PA'],
  ['Rhode Island', 'RI'],
  ['South Carolina', 'SC'],
  ['South Dakota', 'SD'],
  ['Tennessee', 'TN'],
  ['Texas', 'TX'],
  ['Utah', 'UT'],
  ['Vermont', 'VT'],
  ['Virginia', 'VA'],
  ['Washington', 'WA'],
  ['West Virginia', 'WV'],
  ['Wisconsin', 'WI'],
  ['Wyoming', 'WY']
]

Class Method Summary collapse

Class Method Details

.abbreviationsObject



61
62
63
# File 'lib/digital_opera/states.rb', line 61

def self.abbreviations
  to_hash.keys.sort
end

.find_abbreviation_by_name(name) ⇒ Object



73
74
75
# File 'lib/digital_opera/states.rb', line 73

def self.find_abbreviation_by_name(name)
  to_hash.detect{ |k, v| v == name.to_s.capitalize }.first
end

.find_name_by_abbreviation(abbr) ⇒ Object



69
70
71
# File 'lib/digital_opera/states.rb', line 69

def self.find_name_by_abbreviation(abbr)
  to_hash[abbr.to_s.upcase]
end

.namesObject



65
66
67
# File 'lib/digital_opera/states.rb', line 65

def self.names
  to_hash.values.sort
end

.to_collectionObject



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

def self.to_collection
  @collection ||= US_STATES.sort{|a, b| a.first <=> b.first }
end

.to_hashObject



77
78
79
80
81
82
83
# File 'lib/digital_opera/states.rb', line 77

def self.to_hash
  @hash ||= (
    h = {}
    US_STATES.map{ |state| h[state.last] = state.first }
    h
  )
end