Class: PostalAddress
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PostalAddress
- Defined in:
- app/models/postal_address.rb
Overview
create_table :postal_addresses do |t|
t.column :address_line_1, :string
t.column :address_line_2, :string
t.column :city, :string
t.column :state, :string
t.column :zip, :string
t.column :country, :string
t.column :description, :string
t.column :geo_country_id, :integer
t.column :geo_zone_id, :integer
t.timestamps
end
add_index :postal_addresses, :geo_country_id
add_index :postal_addresses, :geo_zone_id
Instance Method Summary collapse
- #summary_line ⇒ Object
- #to_data_hash ⇒ Object
- #to_label(&block) ⇒ Object
- #to_s ⇒ Object
- #zip_eql_to?(zip) ⇒ Boolean
Instance Method Details
#summary_line ⇒ Object
24 25 26 |
# File 'app/models/postal_address.rb', line 24 def summary_line "#{description} : #{address_line_1}, #{city}" end |
#to_data_hash ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/postal_address.rb', line 44 def to_data_hash to_hash(only: [ :address_line_1, :address_line_2, :city, :state, :zip, :country, :description, :created_at, :updated_at ], name: self.try(:contact).try(:party).try(:description) ) end |
#to_label(&block) ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/models/postal_address.rb', line 28 def to_label(&block) if block_given? block.call(self) else "#{description} : #{to_s}" end end |
#to_s ⇒ Object
36 37 38 |
# File 'app/models/postal_address.rb', line 36 def to_s "#{address_line_1}, #{city}, #{state} - #{zip}" end |
#zip_eql_to?(zip) ⇒ Boolean
40 41 42 |
# File 'app/models/postal_address.rb', line 40 def zip_eql_to?(zip) self.zip.downcase.gsub(/[^a-zA-Z0-9]/, "")[0..4] == zip.to_s.downcase.gsub(/[^a-zA-Z0-9]/, "")[0..4] end |