Class: Spree::State

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_all_by_name_or_abbr(name_or_abbr) ⇒ Object


7
8
9
# File 'app/models/spree/state.rb', line 7

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_idObject

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


13
14
15
16
17
18
19
# File 'app/models/spree/state.rb', line 13

def self.states_group_by_country_id
  state_info = Hash.new { |h, k| h[k] = [] }
  self.order('name ASC').each { |state|
    state_info[state.country_id.to_s].push [state.id, state.name]
  }
  state_info
end

Instance Method Details

#<=>(other) ⇒ Object


21
22
23
# File 'app/models/spree/state.rb', line 21

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

#to_sObject


25
26
27
# File 'app/models/spree/state.rb', line 25

def to_s
  name
end