Class: Gaku::State
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gaku::State
- Defined in:
- app/models/gaku/state.rb
Class Method Summary collapse
- .find_all_by_name_or_abbr(name_or_abbr) ⇒ Object
-
.states_group_by_country_iso ⇒ Object
table of { country.id => [ state.id , state.name ] } arrays sorted by name blank is added elsewhere, if needed.
Instance Method Summary collapse
Class Method Details
.find_all_by_name_or_abbr(name_or_abbr) ⇒ Object
12 13 14 |
# File 'app/models/gaku/state.rb', line 12 def self.find_all_by_name_or_abbr(name_or_abbr) where('name = ? OR abbr = ?', name_or_abbr, name_or_abbr) end |
.states_group_by_country_iso ⇒ Object
table of { country.id => [ state.id , state.name ] } arrays sorted by name blank is added elsewhere, if needed
19 20 21 22 23 24 25 |
# File 'app/models/gaku/state.rb', line 19 def self.states_group_by_country_iso state_info = Hash.new { |h, k| h[k] = [] } State.order('name ASC').each do |state| state_info[state.country_iso].push [state.id, state.name] end state_info end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 |
# File 'app/models/gaku/state.rb', line 27 def <=>(other) name <=> other.name end |
#i18n_name ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/models/gaku/state.rb', line 35 def i18n_name carmen_country = Carmen::Country.coded(country_iso) if carmen_country && carmen_country.subregions? && carmen_country.subregions.coded(abbr) carmen_country.subregions.coded(abbr).name else name end end |
#to_s ⇒ Object
31 32 33 |
# File 'app/models/gaku/state.rb', line 31 def to_s i18n_name end |