Class: DigitalOpera::States
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
- .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
      87 88 89  | 
    
      # File 'lib/digital_opera/states.rb', line 87 def self.abbreviations to_hash.keys.sort end  | 
  
.find_abbreviation_by_name(name) ⇒ Object
      99 100 101  | 
    
      # File 'lib/digital_opera/states.rb', line 99 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
      95 96 97  | 
    
      # File 'lib/digital_opera/states.rb', line 95 def self.find_name_by_abbreviation(abbr) to_hash[abbr.to_s.upcase] end  | 
  
.names ⇒ Object
      91 92 93  | 
    
      # File 'lib/digital_opera/states.rb', line 91 def self.names to_hash.values.sort end  | 
  
.to_collection(mapping = {}) ⇒ Object
      57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85  | 
    
      # File 'lib/digital_opera/states.rb', line 57 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  |