Class: Spree::State

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/state.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

#admin_form_preference_names, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

.states_group_by_country_idObject

table of { country.id => [ state.id , state.name ] }, arrays sorted by name blank is added elsewhere, if needed



26
27
28
29
30
31
32
# File 'app/models/spree/state.rb', line 26

def self.states_group_by_country_id
  state_info = Hash.new { |hash, key| hash[key] = [] }
  order(:name).each { |state|
    state_info[state.country_id.to_s].push [state.id, state.name]
  }
  state_info
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
# File 'app/models/spree/state.rb', line 34

def <=>(other)
  name <=> other.name
end

#state_with_countryObject



42
43
44
# File 'app/models/spree/state.rb', line 42

def state_with_country
  "#{name} (#{country})"
end

#to_sObject



38
39
40
# File 'app/models/spree/state.rb', line 38

def to_s
  name
end