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

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

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::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#contact_pointsActiveRecord::Relation<ContactPoint>

Returns:



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

has_many :contact_points, inverse_of: :area_code_object

#lookup_timezoneString?

Returns the resolved timezone name.

Returns:

  • (String, nil)

    the resolved timezone name



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

def lookup_timezone
  # get lat,lng first
  location = "#{city}, #{state_code}"
  results = Geocoder.search location
  return unless (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