Class: Gmaps4rails::ModelHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/gmaps4rails/model_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, gmaps4rails_options) ⇒ ModelHandler

Returns a new instance of ModelHandler.



11
12
13
14
# File 'lib/gmaps4rails/model_handler.rb', line 11

def initialize(object, gmaps4rails_options)
  @options = ::OpenStruct.new(gmaps4rails_options)
  @object  = object
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



5
6
7
# File 'lib/gmaps4rails/model_handler.rb', line 5

def object
  @object
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/gmaps4rails/model_handler.rb', line 5

def options
  @options
end

Instance Method Details

#retrieve_coordinatesObject

saves coordinates according to the various options



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gmaps4rails/model_handler.rb', line 17

def retrieve_coordinates
  return if prevent_geocoding?
  checked_coordinates do
    position? ? set_position : set_lat_lng
    # save normalized address if required
    object.send("#{normalized_address}=", coordinates.first[:matched_address]) if normalized_address
    # Call the callback method to let the user do what he wants with the data
    object.send callback, coordinates.first[:full_data] if callback
    # update checker if required
    object.send("#{checker}=", true) if check_geocoding?
  end
end