adapt JSON parsing in tests to allow for omitted fields

This commit is contained in:
Dennis Luxen 2014-05-16 16:13:25 +02:00
parent a80815d57a
commit 2d498cb88b
2 changed files with 38 additions and 34 deletions

View File

@ -93,10 +93,12 @@ def route_status response
end end
def extract_instruction_list instructions, index, postfix=nil def extract_instruction_list instructions, index, postfix=nil
instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }. if instructions
map { |r| r[index] }. instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }.
map { |r| (r=="" || r==nil) ? '""' : "#{r}#{postfix}" }. map { |r| r[index] }.
join(',') map { |r| (r=="" || r==nil) ? '""' : "#{r}#{postfix}" }.
join(',')
end
end end
def way_list instructions def way_list instructions
@ -112,33 +114,35 @@ def bearing_list instructions
end end
def turn_list instructions def turn_list instructions
types = { if instructions
0 => :none, types = {
1 => :straight, 0 => :none,
2 => :slight_right, 1 => :straight,
3 => :right, 2 => :slight_right,
4 => :sharp_right, 3 => :right,
5 => :u_turn, 4 => :sharp_right,
6 => :sharp_left, 5 => :u_turn,
7 => :left, 6 => :sharp_left,
8 => :slight_left, 7 => :left,
9 => :via, 8 => :slight_left,
10 => :head, 9 => :via,
11 => :enter_roundabout, 10 => :head,
12 => :leave_roundabout, 11 => :enter_roundabout,
13 => :stay_roundabout, 12 => :leave_roundabout,
14 => :start_end_of_street, 13 => :stay_roundabout,
15 => :destination, 14 => :start_end_of_street,
16 => :enter_contraflow, 15 => :destination,
17 => :leave_contraflow 16 => :enter_contraflow,
} 17 => :leave_contraflow
# replace instructions codes with strings }
# "11-3" (enter roundabout and leave a 3rd exit) gets converted to "enter_roundabout-3" # replace instructions codes with strings
instructions.map do |r| # "11-3" (enter roundabout and leave a 3rd exit) gets converted to "enter_roundabout-3"
r[0].to_s.gsub(/^\d*/) do |match| instructions.map do |r|
types[match.to_i].to_s r[0].to_s.gsub(/^\d*/) do |match|
end types[match.to_i].to_s
end.join(',') end
end.join(',')
end
end end
def mode_list instructions def mode_list instructions