Skip to content

Commit

Permalink
Merge pull request #16 from chrismanderson/waypoint-location-name
Browse files Browse the repository at this point in the history
Adds method to provide the location_name on a waypoint
  • Loading branch information
asoesilo committed Apr 14, 2016
2 parents dde0413 + 8e04a54 commit 47a39d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 1 addition & 4 deletions lib/routific/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def parse(routeJson)
# Get all way points for this vehicle
way_points.each do |waypoint_info|
# Get all information for this way point
location_id = waypoint_info["location_id"]
arrival_time = waypoint_info["arrival_time"]
finish_time = waypoint_info["finish_time"]
way_point = RoutificApi::WayPoint.new(location_id, arrival_time, finish_time)
way_point = RoutificApi::WayPoint.new(waypoint_info)
route.addWayPoint(vehicle_name, way_point)
end
end
Expand Down
11 changes: 6 additions & 5 deletions lib/routific/way_point.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module RoutificApi
# This class represents a location to visit in the route
class WayPoint
attr_reader :location_id, :arrival_time, :finish_time
attr_reader :location_id, :arrival_time, :finish_time, :location_name

# Constructor
def initialize(location_id, arrival_time, finish_time)
@location_id = location_id
@arrival_time = arrival_time
@finish_time = finish_time
def initialize(options = {})
@location_id = options['location_id']
@arrival_time = options['arrival_time']
@finish_time = options['finish_time']
@location_name = options['location_name']
end
end
end
9 changes: 7 additions & 2 deletions spec/helper/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ class Factory
WAY_POINT_LOCATION_ID = Faker::Lorem.word
WAY_POINT_ARRIVAL_TIME = "09:00"
WAY_POINT_FINISH_TIME = "09:10"
WAY_POINT = RoutificApi::WayPoint.new( WAY_POINT_LOCATION_ID,
WAY_POINT_ARRIVAL_TIME, WAY_POINT_FINISH_TIME )
WAY_POINT_LOCATION_NAME = Faker::Lorem.word
WAY_POINT = RoutificApi::WayPoint.new({
'location_id' => WAY_POINT_LOCATION_ID,
'arrival_time' => WAY_POINT_ARRIVAL_TIME,
'finish_time' => WAY_POINT_FINISH_TIME,
'location_name' => WAY_POINT_LOCATION_NAME
})

# Factory and constants for route
ROUTE_STATUS = Faker::Lorem.word
Expand Down
4 changes: 4 additions & 0 deletions spec/way_point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
it "has finish_time" do
expect(way_point.finish_time).to eq(Factory::WAY_POINT_FINISH_TIME)
end

it "has a location name" do
expect(way_point.location_name).to eq(Factory::WAY_POINT_LOCATION_NAME)
end
end
end

0 comments on commit 47a39d4

Please sign in to comment.