Class: Office

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Geocodable
Defined in:
app/models/office.rb

Constant Summary collapse

ADDRESS_FIELDS =
[
  :address_line_one,
  :address_line_two,
  :address_town,
  :address_county,
  :address_postcode
].freeze

Instance Method Summary collapse

Methods included from Geocodable

#coordinates, #coordinates=, #geocode, #geocoded?, included, #latitude=, #longitude=, #needs_to_be_geocoded?, #save_with_geocoding, #update_with_geocoding

Instance Method Details

#add_geocoding_failed_errorObject



78
79
80
# File 'app/models/office.rb', line 78

def add_geocoding_failed_error
  errors.add(:geocoding, I18n.t("#{model_name.i18n_key}.geocoding.failure_message"))
end

#field_orderObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/office.rb', line 53

def field_order
  [
    :address_line_one,
    :address_line_two,
    :address_town,
    :address_county,
    :address_postcode,
    :email_address,
    :telephone_number,
    :disabled_access
  ]
end

#full_street_addressObject



70
71
72
# File 'app/models/office.rb', line 70

def full_street_address
  [address_line_one, address_line_two, address_postcode, 'United Kingdom'].reject(&:blank?).join(', ')
end

#has_address_changes?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/office.rb', line 74

def has_address_changes?
  ADDRESS_FIELDS.any? { |field| changed_attributes.include? field }
end

#notify_indexerObject



49
50
51
# File 'app/models/office.rb', line 49

def notify_indexer
  FirmIndexer.handle_aggregate_changed(self)
end

#telephone_numberObject



66
67
68
# File 'app/models/office.rb', line 66

def telephone_number
  super.try { |x| x.gsub(' ', '') }
end