Class: Address

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



28
29
30
# File 'app/models/address.rb', line 28

def self.default
  new :country => Country.find(Spree::Config[:default_country_id])
end

Instance Method Details

#editable?Boolean

can modify an address if it’s not been used in an order (but checkouts controller has finer control)

Returns:

  • (Boolean)


33
34
35
# File 'app/models/address.rb', line 33

def editable?
  new_record? || (shipments.empty? && checkouts.empty?)
end

#full_nameObject



37
38
39
# File 'app/models/address.rb', line 37

def full_name
  self.firstname + " " + self.lastname
end

#phone_validateObject

disconnected since there’s no code to display error messages yet OR matching client-side validation



19
20
21
22
23
24
25
26
# File 'app/models/address.rb', line 19

def phone_validate
  return if phone.blank?
  n_digits = phone.scan(/[0-9]/).size
  valid_chars = (phone =~ /^[-+()\/\s\d]+$/)
  if !(n_digits > 5 && valid_chars)
    errors.add(:phone, "is invalid")
  end
end

#same_as?(other) ⇒ Boolean Also known as: same_as

Returns:

  • (Boolean)


54
55
56
# File 'app/models/address.rb', line 54

def same_as?(other)
  attributes.except("id", "updated_at", "created_at") ==  other.attributes.except("id", "updated_at", "created_at")
end

#state_textObject



41
42
43
# File 'app/models/address.rb', line 41

def state_text
  state.nil? ? state_name : (state.abbr.blank? ? state.name : state.abbr)
end

#to_sObject



59
60
61
# File 'app/models/address.rb', line 59

def to_s
  "#{full_name}: #{address1}"
end

#zoneObject



45
46
47
48
# File 'app/models/address.rb', line 45

def zone
  (state && state.zone) ||
  (country && country.zone)
end

#zonesObject



50
51
52
# File 'app/models/address.rb', line 50

def zones
  Zone.match(self)
end