Module: Geocodable

Included in:
Adviser, Firm
Defined in:
app/models/geocodable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



2
3
4
# File 'app/models/geocodable.rb', line 2

def self.included(model)
  model.scope :geocoded, -> { model.where.not(latitude: nil, longitude: nil) }
end

Instance Method Details

#coordinatesObject



20
21
22
# File 'app/models/geocodable.rb', line 20

def coordinates
  [latitude, longitude]
end

#geocode!(coordinates) ⇒ Object



24
25
26
27
# File 'app/models/geocodable.rb', line 24

def geocode!(coordinates)
  self.latitude, self.longitude = coordinates
  update_columns(latitude: latitude, longitude: longitude)
end

#geocoded?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/geocodable.rb', line 16

def geocoded?
  coordinates.compact.present?
end

#latitude=(value) ⇒ Object



6
7
8
9
# File 'app/models/geocodable.rb', line 6

def latitude=(value)
  value = value.to_f.round(6) unless value.nil?
  write_attribute(:latitude, value)
end

#longitude=(value) ⇒ Object



11
12
13
14
# File 'app/models/geocodable.rb', line 11

def longitude=(value)
  value = value.to_f.round(6) unless value.nil?
  write_attribute(:longitude, value)
end