class DigitalOpera::States
Constants
- US_STATES
Public Class Methods
abbreviations()
click to toggle source
# File lib/digital_opera/states.rb, line 95 def self.abbreviations to_hash.keys.sort end
find_abbreviation_by_name(name)
click to toggle source
# 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)
click to toggle source
# File lib/digital_opera/states.rb, line 103 def self.find_name_by_abbreviation(abbr) to_hash[abbr.to_s.upcase] end
names()
click to toggle source
# File lib/digital_opera/states.rb, line 99 def self.names to_hash.values.sort end
to_collection(mapping={})
click to toggle source
# 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()
click to toggle source
# 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