Class: Gmaps4rails::Direction

Inherits:
Object
  • Object
show all
Includes:
BaseNetMethods
Defined in:
lib/gmaps4rails/api_wrappers/direction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseNetMethods

#base_url, #checked_google_response, #get_response, #parsed_response, #response, #valid_parsed_response?, #valid_response?

Constructor Details

#initialize(start_end, options = {}, output = "pretty") ⇒ Direction

Returns a new instance of Direction.



10
11
12
13
14
15
16
17
18
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 10

def initialize(start_end, options= {}, output = "pretty")
  @ride = OpenStruct.new start_end
  @output    = output
  @protocol  = options.delete(:protocol) || "http"
  @language  = options.delete(:language) || "en"
  @options   = options
  raise_invalid unless valid?
  self.legs  = []
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7

def language
  @language
end

#legsObject

Returns the value of attribute legs.



8
9
10
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 8

def legs
  @legs
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7

def options
  @options
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7

def output
  @output
end

#polylinesObject (readonly)

Returns the value of attribute polylines.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7

def polylines
  @polylines
end

#protocolObject (readonly)

Returns the value of attribute protocol.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7

def protocol
  @protocol
end

#rideObject (readonly)

Returns the value of attribute ride.



7
8
9
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7

def ride
  @ride
end

Instance Method Details

#getObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 20

def get
  checked_google_response do
    #Each element in the legs array specifies a single leg of the journey from the origin to the destination in the calculated route
    parsed_response["routes"].first["legs"].each do |leg|
      extract_polylines(leg) if remove_polylines? 
      self.legs << {
                     "duration"  => { "text" => leg["duration"]["text"], "value" => leg["duration"]["value"].to_f },
                     "distance"  => { "text" => leg["distance"]["text"], "value" => leg["distance"]["value"].to_f },
                     "steps"     => leg["steps"]
                   }
      merge_polylines_with_leg if output == "pretty"
    end
    legs
  end
end