Class: AreaCode

Inherits:
ApplicationRecord show all
Defined in:
app/models/area_code.rb

Overview

== Schema Information

Table name: area_codes
Database name: primary

id :integer not null, primary key
city :string
code :integer
state_code :string
timezone_name :string

Indexes

index_area_codes_on_code (code) UNIQUE

Has many collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#contact_pointsActiveRecord::Relation<ContactPoint>

Returns:

See Also:



18
# File 'app/models/area_code.rb', line 18

has_many :contact_points, inverse_of: :area_code_object

#lookup_timezoneObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/area_code.rb', line 20

def lookup_timezone
  # get lat,lng first
  location = "#{city}, #{state_code}"
  results = Geocoder.search location
  if geo = results.first
    geo.latitude
    geo.longitude
    timezone = Timezone.lookup(geo.latitude, geo.longitude)
    update_column(:timezone_name, timezone.name) unless timezone.name == 'disabled'
  end
end