Class: PostalCode
Overview
== Schema Information
Table name: postal_codes
Database name: primary
id :integer not null, primary key
area_codes :string(200)
code :string(10) not null
dst :boolean
latitude :decimal(15, 10)
longitude :decimal(15, 10)
msa :string(50)
msa_fip :integer
postal_type :string(1)
state_code :string(2)
utc :integer
Indexes
idx_postal_codes_trgm (code) USING gist
index_postal_codes_on_code (code) UNIQUE
index_postal_codes_on_state_code (state_code)
Constant Summary
collapse
- CANADA_POSTAL_CODE_FIRST_LETTER_TO_PROVINCE_CODE =
{
"A" => "NL",
"B" => "NS",
"C" => "PE",
"E" => "NB",
"G" => "QC",
"H" => "QC",
"J" => "QC",
"K" => "ON",
"L" => "ON",
"M" => "ON",
"P" => "ON",
"R" => "MB",
"S" => "SK",
"T" => "AB",
"V" => "BC",
"X" => "NT",
"Y" => "YT"
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#code ⇒ Object
28
|
# File 'app/models/postal_code.rb', line 28
validates :code, :presence => true, :uniqueness => true
|
Class Method Details
.get_state_code_from_postal_code(post_code) ⇒ Object
Instance Method Details
#address_attributes ⇒ Object
54
55
56
|
# File 'app/models/postal_code.rb', line 54
def address_attributes
{:street1 => 'Unknown', :zip => self.code, :state_code => self.state_code, :city => (self.cities.first.city_name rescue nil), :country_iso3 => self.state.country_iso3}
end
|
#addresses ⇒ ActiveRecord::Relation<Address>
29
|
# File 'app/models/postal_code.rb', line 29
has_many :addresses, :foreign_key => :zip, :primary_key => :code
|
#cities ⇒ ActiveRecord::Relation<City>
30
|
# File 'app/models/postal_code.rb', line 30
has_many :cities, :foreign_key => :code, :primary_key => :code
|
#postal_code_statistics ⇒ ActiveRecord::Relation<PostalCodeStatistic>
31
|
# File 'app/models/postal_code.rb', line 31
has_many :postal_code_statistics, :foreign_key => :code, :primary_key => :code
|
32
|
# File 'app/models/postal_code.rb', line 32
belongs_to :state, :foreign_key => :state_code, :primary_key => :code, optional: true
|