Class: Google::Maps::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/google_maps/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, options = {}) ⇒ Route

Returns a new instance of Route.



10
11
12
13
14
15
# File 'lib/google_maps/route.rb', line 10

def initialize(from, to, options = {})
  options = { language: options } unless options.is_a? Hash
  @from = from
  @to = to
  @options = { language: :en }.merge(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/google_maps/route.rb', line 17

def method_missing(method_name, *args, &block)
  if route.legs.first.key?(method_name)
    route.legs.first.send(method_name)
  else
    super
  end
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



8
9
10
# File 'lib/google_maps/route.rb', line 8

def from
  @from
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/google_maps/route.rb', line 8

def options
  @options
end

#toObject

Returns the value of attribute to.



8
9
10
# File 'lib/google_maps/route.rb', line 8

def to
  @to
end

Instance Method Details

#destination_latlongObject



33
34
35
# File 'lib/google_maps/route.rb', line 33

def destination_latlong
  "#{end_location.lat},#{end_location.lng}"
end

#origin_latlongObject



29
30
31
# File 'lib/google_maps/route.rb', line 29

def origin_latlong
  "#{start_location.lat},#{start_location.lng}"
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/google_maps/route.rb', line 25

def respond_to_missing?(method_name, include_private = false)
  route.legs.first.key?(method_name) || super
end