Class: DigitalOpera::States
Constant Summary collapse
- US_STATES =
[ ['Alabama', 'AL'], ['Alaska', 'AK'], ['American Samoa', 'AS'], ['Arizona', 'AZ'], ['Arkansas', 'AR'], ['California', 'CA'], ['Colorado', 'CO'], ['Connecticut', 'CT'], ['Delaware', 'DE'], ['District of Columbia', 'DC'], ['Federated States of Micronesia', 'FM'], ['Florida', 'FL'], ['Georgia', 'GA'], ['Guam', 'GU'], ['Hawaii', 'HI'], ['Idaho', 'ID'], ['Illinois', 'IL'], ['Indiana', 'IN'], ['Iowa', 'IA'], ['Kansas', 'KS'], ['Kentucky', 'KY'], ['Louisiana', 'LA'], ['Maine', 'ME'], ['Marshall Islands', 'MH'], ['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'], ['Northern Mariana Islands', 'MP'], ['Ohio', 'OH'], ['Oklahoma', 'OK'], ['Oregon', 'OR'], ['Palau', 'PW'], ['Pennsylvania', 'PA'], ['Puerto Rico', 'PR'], ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], ['Tennessee', 'TN'], ['Texas', 'TX'], ['Utah', 'UT'], ['Vermont', 'VT'], ['Virgin Islands', 'VI'], ['Virginia', 'VA'], ['Washington', 'WA'], ['West Virginia', 'WV'], ['Wisconsin', 'WI'], ['Wyoming', 'WY'] ]
Class Method Summary collapse
- .abbreviations ⇒ Object
- .find_abbreviation_by_name(name) ⇒ Object
- .find_name_by_abbreviation(abbr) ⇒ Object
- .names ⇒ Object
- .to_collection(mapping = {}) ⇒ Object
- .to_hash ⇒ Object
Class Method Details
.abbreviations ⇒ Object
95 96 97 |
# File 'lib/digital_opera/states.rb', line 95 def self.abbreviations to_hash.keys.sort end |
.find_abbreviation_by_name(name) ⇒ Object
107 108 109 |
# File 'lib/digital_opera/states.rb', line 107 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
103 104 105 |
# File 'lib/digital_opera/states.rb', line 103 def self.find_name_by_abbreviation(abbr) to_hash[abbr.to_s.upcase] end |
.names ⇒ Object
99 100 101 |
# File 'lib/digital_opera/states.rb', line 99 def self.names to_hash.values.sort end |
.to_collection(mapping = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/digital_opera/states.rb', line 65 def self.to_collection(mapping={}) @collection = ( states = US_STATES if mapping[:key].present? || mapping[:value].present? states =US_STATES.map do |state| key = state.last value = state.first if mapping[:value] == :abbr value = state.last elsif mapping[:value] == :name value = state.first end if mapping[:key] == :name key = state.first elsif mapping[:key] == :abbr key = state.last end [value, key] end end states.sort{|a, b| a.first <=> b.first } ) end |
.to_hash ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/digital_opera/states.rb', line 111 def self.to_hash @hash ||= ( h = {} US_STATES.map{ |state| h[state.last] = state.first } h ) end |