Class: Address
- Defined in:
- app/models/address.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#editable? ⇒ Boolean
can modify an address if it’s not been used in an order (but checkouts controller has finer control).
- #full_name ⇒ Object
-
#phone_validate ⇒ Object
disconnected since there’s no code to display error messages yet OR matching client-side validation.
- #same_as?(other) ⇒ Boolean (also: #same_as)
- #state_text ⇒ Object
- #to_s ⇒ Object
- #zone ⇒ Object
- #zones ⇒ Object
Class Method Details
Instance Method Details
#editable? ⇒ Boolean
can modify an address if it’s not been used in an order (but checkouts controller has finer control)
33 34 35 |
# File 'app/models/address.rb', line 33 def editable? new_record? || (shipments.empty? && checkouts.empty?) end |
#full_name ⇒ Object
37 38 39 |
# File 'app/models/address.rb', line 37 def full_name self.firstname + " " + self.lastname end |
#phone_validate ⇒ Object
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
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_text ⇒ Object
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_s ⇒ Object
59 60 61 |
# File 'app/models/address.rb', line 59 def to_s "#{full_name}: #{address1}" end |
#zone ⇒ Object
45 46 47 48 |
# File 'app/models/address.rb', line 45 def zone (state && state.zone) || (country && country.zone) end |