Class: Gmaps4rails::Direction
- Inherits:
-
Object
- Object
- Gmaps4rails::Direction
- Includes:
- BaseNetMethods
- Defined in:
- lib/gmaps4rails/api_wrappers/direction.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#legs ⇒ Object
Returns the value of attribute legs.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#polylines ⇒ Object
readonly
Returns the value of attribute polylines.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#ride ⇒ Object
readonly
Returns the value of attribute ride.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(start_end, options = {}, output = "pretty") ⇒ Direction
constructor
A new instance of Direction.
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, = {}, output = "pretty") @ride = OpenStruct.new start_end @output = output @protocol = .delete(:protocol) || "http" @language = .delete(:language) || "en" @options = raise_invalid unless valid? self.legs = [] end |
Instance Attribute Details
#language ⇒ Object (readonly)
Returns the value of attribute language.
7 8 9 |
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7 def language @language end |
#legs ⇒ Object
Returns the value of attribute legs.
8 9 10 |
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 8 def legs @legs end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7 def output @output end |
#polylines ⇒ Object (readonly)
Returns the value of attribute polylines.
7 8 9 |
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7 def polylines @polylines end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
7 8 9 |
# File 'lib/gmaps4rails/api_wrappers/direction.rb', line 7 def protocol @protocol end |
#ride ⇒ Object (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
#get ⇒ Object
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 |