Sha256: 27bf6a0bd4f57bd4f85610e601e82edac5b2e3016a75249019cd05d4194f6787

Contents?: true

Size: 777 Bytes

Versions: 26

Compression:

Stored size: 777 Bytes

Contents

module Spree
  class State < ActiveRecord::Base
    belongs_to :country, class_name: 'Spree::Country'
    has_many :addresses, dependent: :nullify

    validates :country, :name, presence: true

    def self.find_all_by_name_or_abbr(name_or_abbr)
      where('name = ? OR abbr = ?', name_or_abbr, name_or_abbr)
    end

    # table of { country.id => [ state.id , state.name ] }, arrays sorted by name
    # blank is added elsewhere, if needed
    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

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

    def to_s
      name
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
spree_core-2.2.14 app/models/spree/state.rb
spree_core-2.2.13 app/models/spree/state.rb
spree_core-2.2.12 app/models/spree/state.rb
spree_core-2.2.11 app/models/spree/state.rb
spree_core-2.2.10 app/models/spree/state.rb
spree_core-2.2.9 app/models/spree/state.rb
spree_core-2.1.12 app/models/spree/state.rb
spree_core-2.2.8 app/models/spree/state.rb
spree_core-2.1.11 app/models/spree/state.rb
spree_core-2.2.7 app/models/spree/state.rb
spree_core-2.1.10 app/models/spree/state.rb
spree_core-2.1.9 app/models/spree/state.rb
spree_core-2.2.6 app/models/spree/state.rb
spree_core-2.2.5 app/models/spree/state.rb
spree_core-2.1.8 app/models/spree/state.rb
spree_core-2.2.4 app/models/spree/state.rb
spree_core-2.2.3 app/models/spree/state.rb
spree_core-2.2.2 app/models/spree/state.rb
spree_core-2.1.7 app/models/spree/state.rb
spree_core-2.1.6 app/models/spree/state.rb