Class: Address
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Address
- Defined in:
- app/models/address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #address ⇒ Object
-
#blank? ⇒ Boolean
Country intentionally omitted.
- #is_same_as(addr) ⇒ Object
- #to_s ⇒ Object
- #update_with_note(person, user, address, time_zone, updated_by) ⇒ Object
-
#valid_for_widget_checkout? ⇒ Boolean
Needed because widget checkouts don’t yet have a person_id.
- #values_hash ⇒ Object
Class Method Details
.find_or_create(pers_id) ⇒ Object
45 46 47 48 |
# File 'app/models/address.rb', line 45 def self.find_or_create(pers_id) #refactor to first_or_initialize when Rails 3.2 where(:person_id => pers_id).first || Address.create(:person_id => pers_id) end |
.from_payment(payment) ⇒ Object
37 38 39 |
# File 'app/models/address.rb', line 37 def self.from_payment(payment) payment.try(:customer).try(:address) end |
.unhash(address) ⇒ Object
41 42 43 |
# File 'app/models/address.rb', line 41 def self.unhash(address) (address.is_a? Hash) ? Address.new(address.except(:id, :created_at, :updated_at, :old_mongo_id)) : address end |
Instance Method Details
#==(other) ⇒ Object
75 76 77 |
# File 'app/models/address.rb', line 75 def ==(other) address1 == other.address1 && address2 == other.address2 && city == other.city && state == other.state && zip == other.zip && country == other.country end |
#address ⇒ Object
15 16 17 |
# File 'app/models/address.rb', line 15 def address "#{address1} #{address2}" end |
#blank? ⇒ Boolean
Country intentionally omitted
24 25 26 |
# File 'app/models/address.rb', line 24 def blank? address1.blank? && address2.blank? && city.blank? && state.blank? && zip.blank? end |
#is_same_as(addr) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/models/address.rb', line 28 def is_same_as(addr) return address1.eql?(addr.address1) && address2.eql?(addr.address2) && city.eql?(addr.city) && state.eql?(addr.state) && zip.eql?(addr.zip) && country.eql?(addr.country) end |
#to_s ⇒ Object
19 20 21 |
# File 'app/models/address.rb', line 19 def to_s "#{address1} #{address2} #{city} #{state} #{zip} #{country}" end |
#update_with_note(person, user, address, time_zone, updated_by) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/address.rb', line 50 def update_with_note(person, user, address, time_zone, updated_by) old_addr = to_s() unless is_same_as(address) ["address1", "address2", "city", "state", "zip", "country"].each do |field| self.send("#{field}=", address.send(field)) end if save extra = updated_by.nil? ? "" : " from #{updated_by}" text = "address updated#{extra}" text = text + ", old address was: (#{old_addr})" unless old_addr.blank? note = person.notes.create({ :occurred_at => DateTime.now.in_time_zone(time_zone), :text => text }) note.user = user else return false end end true end |
#valid_for_widget_checkout? ⇒ Boolean
Needed because widget checkouts don’t yet have a person_id
11 12 13 |
# File 'app/models/address.rb', line 11 def !(address1.blank? || city.blank? || state.blank? || zip.blank?) end |
#values_hash ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/address.rb', line 79 def values_hash { :address1 => address1, :address2 => address2, :city => city, :state => state, :zip => zip, :country => country } end |