octranspo 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +26 -0
  4. data/Rakefile +8 -0
  5. data/lib/octranspo.rb +20 -0
  6. data/lib/octranspo/headsign.rb +2539 -0
  7. data/lib/octranspo/headsigns.yml +40565 -0
  8. data/lib/octranspo/landmarks.rb +37 -0
  9. data/lib/octranspo/lingo.rb +125 -0
  10. data/lib/octranspo/lingo/headsign_messages.yml +104 -0
  11. data/lib/octranspo/lingo/headsign_signatures.yml +3 -0
  12. data/lib/octranspo/lingo/landmarks.yml +205 -0
  13. data/lib/octranspo/lingo/roadways.yml +1957 -0
  14. data/lib/octranspo/mobile_resource_methods.rb +98 -0
  15. data/lib/octranspo/mobile_route_data.rb +85 -0
  16. data/lib/octranspo/mobile_route_schedule.rb +118 -0
  17. data/lib/octranspo/mobile_stop_schedule.rb +137 -0
  18. data/lib/octranspo/remote_resource_methods.rb +89 -0
  19. data/lib/octranspo/route.rb +31 -0
  20. data/lib/octranspo/routes.yml +507 -0
  21. data/lib/octranspo/service_date.rb +17 -0
  22. data/lib/octranspo/stations.yml +77 -0
  23. data/lib/octranspo/stop.rb +69 -0
  24. data/lib/octranspo/stop_resource.rb +46 -0
  25. data/lib/octranspo/stops.yml +30696 -0
  26. data/lib/octranspo/version.rb +3 -0
  27. data/octranspo.gemspec +22 -0
  28. data/test/fixtures/mobile_route_data/20090323/route_123_index_0.html +457 -0
  29. data/test/fixtures/mobile_route_data/20090323/route_123_index_1.html +99 -0
  30. data/test/fixtures/mobile_route_data/20090323/route_1_index_0.html +700 -0
  31. data/test/fixtures/mobile_route_data/20090323/route_1_index_1.html +691 -0
  32. data/test/fixtures/mobile_route_data/20090323/route_2_index_0.html +682 -0
  33. data/test/fixtures/mobile_route_data/20090323/route_2_index_1.html +646 -0
  34. data/test/fixtures/mobile_route_data/20100323/route_123_index_0.html +469 -0
  35. data/test/fixtures/mobile_route_data/20100323/route_123_index_1.html +105 -0
  36. data/test/fixtures/mobile_route_data/20100323/route_1_index_0.html +703 -0
  37. data/test/fixtures/mobile_route_data/20100323/route_1_index_1.html +694 -0
  38. data/test/fixtures/mobile_route_data/20100323/route_2_index_0.html +685 -0
  39. data/test/fixtures/mobile_route_data/20100323/route_2_index_1.html +649 -0
  40. data/test/fixtures/mobile_route_data/20100323/route_3_index_0.html +649 -0
  41. data/test/fixtures/mobile_route_data/20100323/route_3_index_1.html +721 -0
  42. data/test/fixtures/mobile_route_schedule/20090323/route_18_direction_2_location_25.html +1038 -0
  43. data/test/fixtures/mobile_route_schedule/20090323/route_1_direction_1_location_0.html +1127 -0
  44. data/test/fixtures/mobile_route_schedule/20090323/route_2_direction_2_location_11.html +1430 -0
  45. data/test/fixtures/mobile_route_schedule/20090323/route_2_direction__location_11.html +104 -0
  46. data/test/fixtures/mobile_route_schedule/20100323/route_1_direction_1_location_0.html +1180 -0
  47. data/test/fixtures/mobile_route_schedule/20100323/route_2_direction_2_location_11.html +1554 -0
  48. data/test/fixtures/mobile_route_schedule/20100323/route_3_direction_1_location_0.html +1082 -0
  49. data/test/fixtures/mobile_route_schedule/20100323/route_3_direction_1_location_1.html +1082 -0
  50. data/test/fixtures/mobile_stop_schedule/20090323/location_1987.yml +198 -0
  51. data/test/fixtures/mobile_stop_schedule/20090323/location_1987_route_index_0.html +1283 -0
  52. data/test/fixtures/mobile_stop_schedule/20090323/location_1987_route_index_1.html +194 -0
  53. data/test/fixtures/mobile_stop_schedule/20090323/location_1987_route_index_2.html +116 -0
  54. data/test/fixtures/mobile_stop_schedule/20090323/location_3058_route_index_12.html +149 -0
  55. data/test/fixtures/mobile_stop_schedule/20090323/location_8789_route_index_0.html +1002 -0
  56. data/test/fixtures/mobile_stop_schedule/20100323/location_1987.yml +209 -0
  57. data/test/fixtures/mobile_stop_schedule/20100323/location_1987_route_index_0.html +1393 -0
  58. data/test/fixtures/mobile_stop_schedule/20100323/location_1987_route_index_1.html +206 -0
  59. data/test/fixtures/mobile_stop_schedule/20100323/location_1987_route_index_2.html +123 -0
  60. data/test/fixtures/mobile_stop_schedule/20100323/location_3058_route_index_12.html +278 -0
  61. data/test/fixtures/mobile_stop_schedule/20100323/location_7558_route_index_0.html +979 -0
  62. data/test/fixtures/mobile_stop_schedule/20100323/location_8789_route_index_0.html +1059 -0
  63. data/test/fixtures/stop_resource/1987.html +126 -0
  64. data/test/test_helper.rb +15 -0
  65. data/test/unit/headsign_test.rb +34 -0
  66. data/test/unit/lingo_test.rb +139 -0
  67. data/test/unit/mobile_resource_methods_test.rb +25 -0
  68. data/test/unit/mobile_route_data_test.rb +124 -0
  69. data/test/unit/mobile_route_schedule_test.rb +210 -0
  70. data/test/unit/mobile_stop_schedule_test.rb +153 -0
  71. data/test/unit/service_date_test.rb +27 -0
  72. data/test/unit/stop_resource_test.rb +26 -0
  73. metadata +251 -0
@@ -0,0 +1,126 @@
1
+
2
+
3
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
+ <html lang="EN">
5
+ <head>
6
+ <title>OC Travel Planner</title>
7
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
8
+ <meta http-equiv="expires" content="0"/>
9
+ <link rel="stylesheet" type="text/css" href="style.css">
10
+ <script type="text/javascript" language="JavaScript" src="js/validate.js"></script>
11
+ </head>
12
+ <body>
13
+
14
+
15
+ <script type="text/javascript" language="JavaScript" src="js/sniffer.js"></script>
16
+ <script type="text/javascript" language="JavaScript">
17
+ if (!detect())
18
+ {
19
+ document.open();
20
+ document.writeln('<div class="badBrowser">The travel planner works best with Netscape 6.1 and up, or Explorer 5 and up. If you are using other browsers or lower versions you may encounter problems. Would you like to proceed?</div>');
21
+ document.close();
22
+ }
23
+ </script>
24
+
25
+ <noscript>
26
+ <div class="noscript">
27
+ <h2>This site uses Javascript. Please enable Javascript in your web browser
28
+ before continuing.</h2>
29
+ </div>
30
+ </noscript>
31
+ <form name="tp_from560" method="get" action="From560Confirm.oci;jsessionid=1FA018169BEF95E84987E83622F4D35E">
32
+ <table cellpadding="0" cellspacing="0" summary="" class="banner">
33
+ <tr>
34
+ <td width="83"><img src="tripPlanning/images/tp_banner1.gif" width="83" height="43"></td>
35
+ <td width="718"><img src="tripPlanning/images/tp_banner2.gif" width="668" height="43"></td>
36
+ </tr>
37
+ </table>
38
+ <table cellpadding="0" cellspacing="0" summary="" class="progress">
39
+ <tr>
40
+ <td width="110"><img src="tripPlanning/images/tp_progress1.gif" width="110" height="30"></td>
41
+ <td width="20">&nbsp;</td>
42
+ <td width="620" class="right"><img src="tripPlanning/images/tp_25percent.gif" width="596" height="25"></td>
43
+ </tr>
44
+ </table>
45
+ <table cellpadding="0" cellspacing="0" summary="" class="progressDesc">
46
+ <tr>
47
+ <td width="110"><img src="tripPlanning/images/tp_progressDesc1.gif" width="83" height="59"></td>
48
+ <td width="30">&nbsp;</td>
49
+ <td width="60" class="stepText">&nbsp;</td>
50
+ <td width="90" class="stepText">&nbsp;</td>
51
+ <td width="60" class="stepText">&nbsp;</td>
52
+ <td width="90" class="stepText">&nbsp;</td>
53
+ <td width="60" class="stepText">&nbsp;</td>
54
+ <td width="90" class="stepText">&nbsp;</td>
55
+ <td width="60" class="stepText">&nbsp;</td>
56
+ <td width="90" class="stepText">&nbsp;</td>
57
+ </tr>
58
+ </table>
59
+ <table cellpadding="0" cellspacing="0" summary="" class="stepName">
60
+ <tr>
61
+ <td width="85"><img src="tripPlanning/images/tp_stepName1.gif" width="83" height="23"></td>
62
+ <td width="665"><img src="tripPlanning/images/text_fromWhere.gif" width="259" height="21"></td>
63
+ </tr>
64
+ </table>
65
+ <table cellpadding="0" cellspacing="0" summary="" class="tabs">
66
+ <tr>
67
+ <td width="63" rowspan="2" background="tripPlanning/images/tp_sideShim.gif" class="top"><img src="tripPlanning/images/tp_side.gif" width="63" height="300"></td>
68
+ <td width="30" height="58" class="tp_boxTop1">&nbsp;</td>
69
+ <td width="85" height="58" class="tp_boxTop2"><a href="linkFromAddress.oci"><img src="tripPlanning/images/tp_addressOff.gif" alt="Address" title="Address" width="85" height="38" border="0"></a></td>
70
+ <td width="85" height="58" class="tp_boxTop2"><a href="linkFromIntersection.oci"><img src="tripPlanning/images/tp_intersectionOff.gif" alt="Intersection" title="Intersection" width="85" height="38" border="0"></a></td>
71
+ <td width="85" height="58" class="tp_boxTop2"><a href="FromLandmarkSetup.oci"><img src="tripPlanning/images/tp_landmarkOff.gif" alt="Landmark" title="Landmark" width="85" height="38" border="0"></a></td>
72
+ <td width="95" height="58" class="tp_boxTop2"><img src="tripPlanning/images/tp_560On.gif" alt="560-1000" title="560-1000" width="95" height="38" border="0"></td>
73
+ <td width="85" height="58" class="tp_boxTop2"><a href="linkFromMap.oci"><img src="tripPlanning/images/tp_mapOff.gif" alt="Map" title="Map" width="85" height="38" border="0"></a></td>
74
+ <td width="85" height="58" class="tp_boxTop2"><a href="linkFromHistory.oci"><img src="tripPlanning/images/tp_historyOff.gif" alt="History" title="Map" width="85" height="38" border="0"></a></td>
75
+ <td width="97" height="58" class="tp_boxTop2"><img src="tripPlanning/images/tp_line.gif" width="97" height="38"></td>
76
+ <td width="40" height="58" class="tp_boxTop3">&nbsp;</td>
77
+ </tr>
78
+ <tr>
79
+ <td width="30" class="tp_boxLeft">&nbsp;</td>
80
+ <td width="617" height="270" class="tp_box" colspan="7">
81
+ <table cellpadding="0" cellspacing="0" width="100%" height="100%">
82
+ <tr>
83
+ <td width="240">&nbsp;</td>
84
+ <td height="50" width="80" class="center"><img src="tripPlanning/images/tp_img560.gif" width="70" height="43"></td>
85
+ <td colspan="5" width="257">&nbsp;</td>
86
+ </tr>
87
+ <tr>
88
+ <td class="formPadding3" colspan="7">
89
+ <div class="padTop">&nbsp;</div>
90
+ <table cellpadding="0" cellspacing="0" summary="">
91
+ <tr>
92
+ <td class="right">
93
+ <div class="instruction">Is this the right bus stop?</div>
94
+
95
+
96
+ (1987)
97
+
98
+
99
+ SOMERSET O-W / BRONSON
100
+ <input type="hidden" name="from560Code" value="1987">
101
+
102
+ </td>
103
+ <td class="padRight" nowrap> &nbsp;&nbsp;
104
+ <input name="ok" id="ok" type="image" src="tripPlanning/images/ok.gif" width="59" height="32" alt="OK" title="OK">
105
+ <a href="linkFrom560.oci"><img src="tripPlanning/images/no.gif" width="59" height="32" alt="NO" title="NO" border="0"></a>
106
+ </td>
107
+ </tr>
108
+ </table>
109
+ </td>
110
+ </tr>
111
+ </table>
112
+ </td>
113
+ <td width="40" class="tp_boxRight">&nbsp;</td>
114
+ </tr>
115
+ </table>
116
+ <table cellpadding="0" cellspacing="0" summary="" class="last">
117
+ <tr>
118
+ <td width="63"><img src="tripPlanning/images/tp_bottom1.gif" width="63" height="37"></td>
119
+ <td width="30" class="tp_boxBottom1">&nbsp;</td>
120
+ <td width="617" class="tp_boxBottom2">&nbsp;</td>
121
+ <td width="40" class="tp_boxBottom3">&nbsp;</td>
122
+ </tr>
123
+ </table>
124
+ </form>
125
+ </body>
126
+ </html>
@@ -0,0 +1,15 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "octranspo"
4
+ require "test/unit"
5
+ require "active_support/test_case"
6
+
7
+ class Date
8
+ # date.at('12:00') => time object representing the date at noon
9
+ def at (string)
10
+ matches = /^(\d\d)(:)*(\d\d)$/.match(string)
11
+ hh, mm = Integer(matches[1]), Integer(matches[3])
12
+ duration = hh.hours + mm.minutes
13
+ to_time.in_time_zone.change :hour => hh, :min => mm
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ require "#{File.dirname(File.dirname(__FILE__))}/test_helper"
2
+
3
+ module OCTranspo
4
+ class HeadsignTest < ActiveSupport::TestCase
5
+
6
+ test "1 OTTAWA ROCKCLIFFE headsign" do
7
+ assert_equal "1 OTTAWA ROCKCLIFFE", OCTranspo::Headsign.find(1, "OTTAWA-ROCKCLIFFE", [{:code => "8789"}])
8
+ end
9
+
10
+ test "1X DOWNTOWN headsign" do
11
+ assert_equal "1 DOWNTOWN", OCTranspo::Headsign.find(1, "OTTAWA-ROCKCLIFFE", [{:code => "3009"}])
12
+ end
13
+
14
+ test "1 SOUTH KEYS headsign" do
15
+ assert_equal "1 SOUTH KEYS", OCTranspo::Headsign.find(1, "SOUTH KEYS", [{:code => "3037"}])
16
+ end
17
+
18
+ test "1X BILLINGS BRIDGE headsign" do
19
+ assert_equal "1X BILLINGS BRIDGE", OCTranspo::Headsign.find(1, "SOUTH KEYS", [{:code => "3034"}])
20
+ end
21
+
22
+ test "2 BAYSHORE headsign" do
23
+ assert_equal "2 BAYSHORE", OCTranspo::Headsign.find(2, "BAYSHORE", [{:code => "3050"}])
24
+ end
25
+
26
+ test "2 WESTBORO headsign" do
27
+ assert_equal "2 WESTBORO", OCTranspo::Headsign.find(2, "BAYSHORE", [{:code => "3012"}])
28
+ end
29
+
30
+ test "2 DOWNTOWN headsign" do
31
+ assert_equal "2 DOWNTOWN", OCTranspo::Headsign.find(2, "DOWNTOWN", [{:code => "3009"}])
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,139 @@
1
+ require "#{File.dirname(File.dirname(__FILE__))}/test_helper"
2
+
3
+ module OCTranspo
4
+ class LingoTest < ActiveSupport::TestCase
5
+
6
+ include Lingo
7
+
8
+ test "translate location lingo for addresses" do
9
+ assert_equal "360 Coventry Rd.", translate_location("COVENTRY / AD. 360")
10
+ end
11
+
12
+ test "translate location lingo for addresses with back slashes" do
13
+ assert_equal "1520 Caldwell Ave.", translate_location("CALDWELL \\ AD. 1520")
14
+ end
15
+
16
+ test "translate location lingo for intersections" do
17
+ assert_equal "Somerset St. at Bronson Ave.", translate_location("SOMERSET O-W / BRONSON")
18
+ assert_equal "Coventry Rd. at Jetform Park", translate_location("COVENTRY / PARC JETFORM PARK")
19
+ assert_equal "Ballard Ct. at Blair Rd.", translate_location("BALLARD / BLAIR")
20
+ assert_equal "Ballard Rd. at Blair Rd.", translate_location("NRC ROAD BALLARD / BLAIR")
21
+ assert_equal "Blair Rd. at Meadowbrook Rd.", translate_location("BLAIR / MEADOWBROOK")
22
+ assert_equal "Broadview Ave. at Notre Dame High School", translate_location("BROADVIEW / É.S. NOTRE DAME")
23
+ assert_equal "Bridgestone Dr. at Windways Crescent", translate_location("BRIDGESTONE / WINDWAYS")
24
+ assert_equal "Eagleson Rd. at Cadence Gate", translate_location("EAGLESON / CADENCE")
25
+ assert_equal "Shirley’s Brook Dr. at Marconi Ave.", translate_location("SHIRLEY'S BROOK / MARCONI")
26
+ assert_equal "Stittsville Main St. at Bandelier Way", translate_location("MAIN STITTSVILLE / BANDELIER")
27
+ assert_equal "Cyrville Rd. at Maxime St.", translate_location("CYRVILLE / MAXIME")
28
+ assert_equal "Orléans Blvd. at Boyer Rd.", translate_location("ORLÉANS / BOYER")
29
+ assert_equal "Lees Ave. at Main St.", translate_location("LEES / MAIN")
30
+ assert_equal "Strandherd Dr. at Jockvale Rd.", translate_location("STRANDHERD / JOCKVALE")
31
+ assert_equal "Jeanne d’Arc Blvd. at Terry Fox Elementary School", translate_location("JEANNE D'ARC / ÉCOLE TERRY FOX SCHOOL")
32
+ assert_equal "Promenade Ave. at Terrasses de la Chaudière", translate_location("PROMENADE / TERRASSES DE LA CHAUDIÈRE")
33
+ assert_equal "Scott St. at Bayview Rd.", translate_location("SCOTT / BAYVIEW")
34
+ end
35
+
36
+ test "translate location lingo for intersections with back slashes" do
37
+ assert_equal "Ages Dr. at Hawthorne Rd.", translate_location("AGES \\ HAWTHORNE")
38
+ end
39
+
40
+ test "translate location lingo for stations" do
41
+ assert_equal "Bayshore Station", translate_location("BAYSHORE")
42
+ assert_equal "Baseline Station", translate_location("BASELINE")
43
+ assert_equal "Blair Station", translate_location("BLAIR")
44
+ end
45
+
46
+ test "translate location lingo for busway platforms at stations" do
47
+ assert_equal "Bayshore Station, Platform 1A", translate_location("BAYSHORE 1A")
48
+ assert_equal "Baseline Station, Platform 1E", translate_location("BASELINE 1E")
49
+ assert_equal "Lebreton Station, Platform 1A", translate_location("LEBRETON 1A")
50
+ assert_equal "St. Laurent Station, Platform 2A", translate_location("ST LAURENT 2A")
51
+ assert_equal "Tunney’s Pasture Station, Platform 1A", translate_location("TUNNEY'S PASTURE 1A")
52
+ end
53
+
54
+ test "translate location lingo for busway platforms at landmarks" do
55
+ assert_equal "Rideau Centre, Platform 3A", translate_location("RIDEAU 3A")
56
+ assert_equal "Rideau Centre, Platform 4A", translate_location("RIDEAU 4A")
57
+ end
58
+
59
+ test "translate location lingo for train platforms" do
60
+ assert_equal "Bayview Station, O-Train Platform", translate_platform("O-TRAIN BAYVIEW")
61
+ assert_equal "Carleton Station, Southbound Platform", translate_platform("O-TRAIN CARLETON S.")
62
+ assert_equal "Carleton Station, Northbound Platform", translate_platform("O-TRAIN CARLETON N.")
63
+ end
64
+
65
+ test "translate landmarks" do
66
+ assert_equal "Colonnade Rd. at OC Transpo Garage", translate_location("MERIVALE GARAGE / GARAGE MERIVALE")
67
+ assert_equal "Colonnade Rd. at OC Transpo Garage", translate_location("COLONNADE / GARAGE O.C. TRANSPO GARAGE")
68
+ end
69
+
70
+ test "translate locations in hull" do
71
+ assert_equal "Rue Laurier at Rue Élisabeth-Bruyère", translate_location("LAURIER / ÉLISABETH-BRUYÈRE")
72
+ assert_equal "Boulevard Des Allumettières at Rue Laurier", translate_location("ALLUMETTIÈRES / LAURIER")
73
+ end
74
+
75
+ test "translate broken lingo" do
76
+ assert_equal "Tunney’s Pasture Station, Platform 4A", translate_location("TUNNEY'S PASTURE4A")
77
+ assert_equal "Heron Station, Platform 4A", translate_location("HERON 4A ")
78
+ assert_equal "Heron Rd. at Edge Hill Pl.", translate_location("HERON/EDGEHILL")
79
+ assert_equal "Dauphin Rd. at Hillcrest High School", translate_location("NODE4518")
80
+ assert_equal "Campus Ave. at Library Rd.", translate_location("CAMPUS / COMMONS")
81
+ end
82
+
83
+ test "recognize lingo that represents an address" do
84
+ assert address?("COVENTRY / AD. 360")
85
+ assert ! address?("SOMERSET O-W / BRONSON")
86
+ assert ! address?("BAYSHORE")
87
+ assert ! address?("BAYSHORE 1A")
88
+ end
89
+
90
+ test "recognize lingo that represents an intersection" do
91
+ assert intersection?("SOMERSET O-W / BRONSON")
92
+ assert ! intersection?("COVENTRY / AD. 360")
93
+ assert ! intersection?("BAYSHORE")
94
+ assert ! intersection?("BAYSHORE 1A")
95
+ end
96
+
97
+ test "recognize lingo that represents a platform" do
98
+ assert platform?("BAYSHORE 1A")
99
+ assert ! platform?("SOMERSET O-W / BRONSON")
100
+ assert ! platform?("COVENTRY / AD. 360")
101
+ assert ! platform?("BAYSHORE")
102
+ end
103
+
104
+ test "extract address parts from lingo" do
105
+ extracted = extract_address_from("COVENTRY / AD. 360")
106
+ assert_equal "360", extracted[:number]
107
+ assert_equal "COVENTRY", extracted[:street]
108
+ end
109
+
110
+ test "extract intersection parts from lingo" do
111
+ extracted = extract_intersection_from("SOMERSET O-W / BRONSON")
112
+ assert_equal "SOMERSET O-W", extracted.first
113
+ assert_equal "BRONSON", extracted.last
114
+ end
115
+
116
+ test "extract platform parts from lingo" do
117
+ extracted = extract_platform_from("BAYSHORE 1A")
118
+ assert_equal "BAYSHORE", extracted[:station]
119
+ assert_equal "1A", extracted[:platform]
120
+ end
121
+
122
+ test "extract platform parts from lingo with two word station name" do
123
+ extracted = extract_platform_from("BILLINGS BRIDGE 1A")
124
+ assert_equal "BILLINGS BRIDGE", extracted[:station]
125
+ assert_equal "1A", extracted[:platform]
126
+ end
127
+
128
+ test "extract platform parts from lingo with extra space" do
129
+ extracted = extract_platform_from("LEBRETON 1A")
130
+ assert_equal "LEBRETON", extracted[:station]
131
+ assert_equal "1A", extracted[:platform]
132
+ end
133
+
134
+ test "translate headsign lingo" do
135
+ assert_equal "AIRPORT", translate_headsign_message("AIRPORT / AéROPORT")
136
+ assert_equal "LOCAL NORTH", translate_headsign_message("LOCAL NORTH/NORD")
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,25 @@
1
+ require "#{File.dirname(File.dirname(__FILE__))}/test_helper"
2
+
3
+ module OCTranspo
4
+ class MobileResourceMethodsTest < ActiveSupport::TestCase
5
+
6
+ include MobileResourceMethods
7
+
8
+ def date
9
+ @date ||= Date.parse("20090303")
10
+ end
11
+
12
+ test "extracting time from text on a specific date" do
13
+ assert_equal date.at('04:00'), extract_time_from("4:00 AM", :date => date)
14
+ assert_equal date.at('06:30'), extract_time_from("6:30 AM", :date => date)
15
+ assert_equal date.at('12:00'), extract_time_from("12:00 PM", :date => date)
16
+ assert_equal date.at('15:30'), extract_time_from("3:30 PM", :date => date)
17
+ assert_equal date.at('23:57'), extract_time_from("11:57 PM", :date => date)
18
+ assert_equal date.next.at('02:30'), extract_time_from("2:30 AM", :date => date)
19
+ assert_equal date.next.at('03:59'), extract_time_from("3:59 AM", :date => date)
20
+ end
21
+
22
+ test "extracting flags from text" do
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,124 @@
1
+ require "#{File.dirname(File.dirname(__FILE__))}/test_helper"
2
+
3
+ module OCTranspo
4
+ class MobileRouteDataTest < ActiveSupport::TestCase
5
+
6
+ def date
7
+ @date ||= Date.parse("20100323")
8
+ end
9
+
10
+ def setup
11
+ OCTranspo::MobileRouteData.use_fixtures!
12
+ end
13
+
14
+ def teardown
15
+ OCTranspo::MobileRouteData.reset!
16
+ end
17
+
18
+ test "find two sets of data for route 1" do
19
+ route_data = OCTranspo::MobileRouteData.find(1, :date => date)
20
+ assert_equal 2, route_data.size
21
+
22
+ assert_equal "1", route_data[0][:route]
23
+ assert_equal "OTTAWA-ROCKCLIFFE", route_data[0][:direction]
24
+ assert_equal "2", route_data[0][:direction_index]
25
+ assert_equal 67, route_data[0][:stops].size
26
+
27
+ assert_equal "1", route_data[1][:route]
28
+ assert_equal "SOUTH KEYS", route_data[1][:direction]
29
+ assert_equal "1", route_data[1][:direction_index]
30
+ assert_equal 66, route_data[1][:stops].size
31
+ end
32
+
33
+ test "find two sets of data for route 2" do
34
+ route_data = OCTranspo::MobileRouteData.find(2, :date => date)
35
+ assert_equal 2, route_data.size
36
+
37
+ assert_equal "2", route_data[0][:route]
38
+ assert_equal "BAYSHORE", route_data[0][:direction]
39
+ assert_equal "2", route_data[0][:direction_index]
40
+ assert_equal 65, route_data[0][:stops].size
41
+
42
+ assert_equal "2", route_data[1][:route]
43
+ assert_equal "DOWNTOWN / CENTRE-VILLE", route_data[1][:direction]
44
+ assert_equal "1", route_data[1][:direction_index]
45
+ assert_equal 61, route_data[1][:stops].size
46
+ end
47
+
48
+ test "find one sets of data for route 123" do
49
+ route_data = OCTranspo::MobileRouteData.find(123, :date => date)
50
+ assert_equal 1, route_data.size
51
+
52
+ assert_equal "123", route_data[0][:route]
53
+ assert_equal "GLOUCESTER N. & BLAIR", route_data[0][:direction]
54
+ assert_equal "1", route_data[0][:direction_index]
55
+ assert_equal 41, route_data[0][:stops].size
56
+ end
57
+
58
+ test "find first set of data for bus route 2" do
59
+ route_direction = OCTranspo::MobileRouteData.find_one_direction(:route => 2, :index => 0, :date => date)
60
+
61
+ assert route_direction, "route direction is nil"
62
+
63
+ assert_equal "2", route_direction[:route]
64
+ assert_equal "BAYSHORE", route_direction[:direction]
65
+ assert_equal "2", route_direction[:direction_index]
66
+
67
+ assert route_direction[:stops].all? {|stop| stop.is_a?(Hash) }, "Some stops aren’t hashes!"
68
+
69
+ first_stop = route_direction[:stops].first
70
+ assert_equal "RIDEAU 4A", first_stop[:name]
71
+ assert_equal "3009", first_stop[:number]
72
+ assert_equal "RIDEAU", first_stop[:station]
73
+ assert_equal "4A", first_stop[:platform]
74
+
75
+ second_stop = route_direction[:stops].second
76
+ assert_equal "WELLINGTON / METCALFE", second_stop[:name]
77
+ assert_equal "7691", second_stop[:number]
78
+ assert second_stop[:station].nil?
79
+ assert second_stop[:platform].nil?
80
+
81
+ last_stop = route_direction[:stops].last
82
+ assert_equal "BAYSHORE 3A", last_stop[:name]
83
+ assert_equal "3050", last_stop[:number]
84
+ assert_equal "BAYSHORE", last_stop[:station]
85
+ assert_equal "3A", last_stop[:platform]
86
+ end
87
+
88
+ test "find opposite set of data for bus route 2" do
89
+ route_direction = OCTranspo::MobileRouteData.find_one_direction(:route => 2, :index => 1, :date => date)
90
+
91
+ assert_equal "2", route_direction[:route]
92
+ assert_equal "DOWNTOWN / CENTRE-VILLE", route_direction[:direction]
93
+ assert_equal "1", route_direction[:direction_index]
94
+
95
+ assert route_direction[:stops].all? {|stop| stop.is_a?(Hash) }, "Some stops aren’t hashes!"
96
+
97
+ first_stop = route_direction[:stops].first
98
+ assert_equal "3050", first_stop[:number]
99
+ assert_equal "BAYSHORE 4B", first_stop[:name]
100
+ assert_equal "BAYSHORE", first_stop[:station]
101
+ assert_equal "4B", first_stop[:platform]
102
+
103
+ last_stop = route_direction[:stops].last
104
+ assert_equal "3009", last_stop[:number]
105
+ assert_equal "RIDEAU 3A", last_stop[:name]
106
+ assert_equal "RIDEAU", last_stop[:station]
107
+ assert_equal "3A", last_stop[:platform]
108
+ end
109
+
110
+ test "url_for" do
111
+ expected = "http://www.octranspo.com/mobileweb/jnot/post.routelist.schedules.oci?rangeIndex=5&day=20100323&route=2&routeIndex=0"
112
+ criteria = {:route => 2, :index => 0, :date => date}
113
+ assert_equal expected, OCTranspo::MobileRouteData.url_for(criteria)
114
+ criteria = {:route => 2, :date => date}
115
+ assert_equal expected, OCTranspo::MobileRouteData.url_for(criteria)
116
+ end
117
+
118
+ test "url_for with index option" do
119
+ expected = "http://www.octranspo.com/mobileweb/jnot/post.routelist.schedules.oci?rangeIndex=5&day=20100323&route=2&routeIndex=1"
120
+ criteria = {:route => 2, :index => 1, :date => date}
121
+ assert_equal expected, OCTranspo::MobileRouteData.url_for(criteria)
122
+ end
123
+ end
124
+ end