Class: TollBooth::RouteStep

Inherits:
Object
  • Object
show all
Defined in:
lib/toll_booth/route_step.rb

Overview

a direction to take for a given route direction steps have the following attributes

  • distance (in miles)

  • travel_time (in seconds)

  • latitude

  • longitude

  • html_description

  • description (html stripped)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#distanceObject

Returns the value of attribute distance.



11
12
13
# File 'lib/toll_booth/route_step.rb', line 11

def distance
  @distance
end

#html_descriptionObject

Returns the value of attribute html_description.



11
12
13
# File 'lib/toll_booth/route_step.rb', line 11

def html_description
  @html_description
end

#latitudeObject

Returns the value of attribute latitude.



11
12
13
# File 'lib/toll_booth/route_step.rb', line 11

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



11
12
13
# File 'lib/toll_booth/route_step.rb', line 11

def longitude
  @longitude
end

#travel_timeObject

Returns the value of attribute travel_time.



11
12
13
# File 'lib/toll_booth/route_step.rb', line 11

def travel_time
  @travel_time
end

Class Method Details

.parse(json) ⇒ Object

parses the step from the json supplied



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/toll_booth/route_step.rb', line 21

def parse(json)
  route_steps = []
  json.each do |s|
    route_step = new
    route_step.html_description = s["descriptionHtml"]
    route_step.travel_time = s["Duration"]["seconds"]
    route_step.distance  = s["Distance"]["html"]
    route_step.latitude  = s["Point"]["coordinates"][0]
    route_step.longitude = s["Point"]["coordinates"][1]

    route_steps << route_step
  end

  route_steps
end

Instance Method Details

#descriptionString

strips any html from the html_description_attribute

Returns:

  • (String)


15
16
17
# File 'lib/toll_booth/route_step.rb', line 15

def description
  @html_description.gsub(/<\/?[^>]*>/, "")
end