Sha256: 1f3f004a8999d7492445f9b5423731188ee951c04f323c2426d41e933e4b51fc

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module TollBooth
  #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)
  class RouteStep
    attr_accessor :distance, :travel_time, :latitude, :longitude, :html_description

    # strips any html from the html_description_attribute
    # @return [String]
    def description
      @html_description.gsub(/<\/?[^>]*>/, "")
    end

    class << self
      # parses the step from the json supplied
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
dpickett-toll_booth-0.1.0 lib/toll_booth/route_step.rb
toll_booth-0.2.0 lib/toll_booth/route_step.rb
toll_booth-0.1.0 lib/toll_booth/route_step.rb