Skip to content

Commit e7427fe

Browse files
committed
Merge pull request #14 from transitland/extended_route_types
added support and testing for extended route types
2 parents 2b96bd2 + cdcc59b commit e7427fe

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

lib/gtfs/route.rb

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,153 @@ class Route
1010
required_file true
1111
uses_filename 'routes.txt'
1212

13+
VEHICLE_TYPES = {
14+
nil => nil,
15+
:'' => nil,
16+
# Basic GTFS
17+
:'0' => :'Tram',
18+
:'1' => :'Metro',
19+
:'2' => :'Rail',
20+
:'3' => :'Bus',
21+
:'4' => :'Ferry',
22+
:'5' => :'Cablecar',
23+
:'6' => :'Gondola',
24+
:'7' => :'Funicular',
25+
# Extended vehicle types
26+
# https://support.google.com/transitpartners/answer/3520902?hl=en
27+
:'100' => :'Railway Service',
28+
:'101' => :'High Speed Rail Service',
29+
:'102' => :'Long Distance Trains',
30+
:'103' => :'Inter Regional Rail Service',
31+
:'104' => :'Car Transport Rail Service',
32+
:'105' => :'Sleeper Rail Service',
33+
:'106' => :'Regional Rail Service',
34+
:'107' => :'Tourist Railway Service',
35+
:'108' => :'Rail Shuttle (Within Complex)',
36+
:'109' => :'Suburban Railway',
37+
:'110' => :'Replacement Rail Service',
38+
:'111' => :'Special Rail Service',
39+
:'112' => :'Lorry Transport Rail Service',
40+
:'113' => :'All Rail Services',
41+
:'114' => :'Cross-Country Rail Service',
42+
:'115' => :'Vehicle Transport Rail Service',
43+
:'116' => :'Rack and Pinion Railway',
44+
:'117' => :'Additional Rail Service',
45+
:'200' => :'Coach Service',
46+
:'201' => :'International Coach Service',
47+
:'202' => :'National Coach Service',
48+
:'203' => :'Shuttle Coach Service',
49+
:'204' => :'Regional Coach Service',
50+
:'205' => :'Special Coach Service',
51+
:'206' => :'Sightseeing Coach Service',
52+
:'207' => :'Tourist Coach Service',
53+
:'208' => :'Commuter Coach Service',
54+
:'209' => :'All Coach Services',
55+
:'300' => :'Suburban Railway Service',
56+
:'400' => :'Urban Railway Service',
57+
:'401' => :'Metro Service',
58+
:'402' => :'Underground Service',
59+
:'403' => :'Urban Railway Service',
60+
:'404' => :'All Urban Railway Services',
61+
:'405' => :'Monorail',
62+
:'500' => :'Metro Service',
63+
:'600' => :'Underground Service',
64+
:'700' => :'Bus Service',
65+
:'701' => :'Regional Bus Service',
66+
:'702' => :'Express Bus Service',
67+
:'703' => :'Stopping Bus Service',
68+
:'704' => :'Local Bus Service',
69+
:'705' => :'Night Bus Service',
70+
:'706' => :'Post Bus Service',
71+
:'707' => :'Special Needs Bus',
72+
:'708' => :'Mobility Bus Service',
73+
:'709' => :'Mobility Bus for Registered Disabled',
74+
:'710' => :'Sightseeing Bus',
75+
:'711' => :'Shuttle Bus',
76+
:'712' => :'School Bus',
77+
:'713' => :'School and Public Service Bus',
78+
:'714' => :'Rail Replacement Bus Service',
79+
:'715' => :'Demand and Response Bus Service',
80+
:'716' => :'All Bus Services',
81+
:'800' => :'Trolleybus Service',
82+
:'900' => :'Tram Service',
83+
:'901' => :'City Tram Service',
84+
:'902' => :'Local Tram Service',
85+
:'903' => :'Regional Tram Service',
86+
:'904' => :'Sightseeing Tram Service',
87+
:'905' => :'Shuttle Tram Service',
88+
:'906' => :'All Tram Services',
89+
:'1000' => :'Water Transport Service',
90+
:'1001' => :'International Car Ferry Service',
91+
:'1002' => :'National Car Ferry Service',
92+
:'1003' => :'Regional Car Ferry Service',
93+
:'1004' => :'Local Car Ferry Service',
94+
:'1005' => :'International Passenger Ferry Service',
95+
:'1006' => :'National Passenger Ferry Service',
96+
:'1007' => :'Regional Passenger Ferry Service',
97+
:'1008' => :'Local Passenger Ferry Service',
98+
:'1009' => :'Post Boat Service',
99+
:'1010' => :'Train Ferry Service',
100+
:'1011' => :'Road-Link Ferry Service',
101+
:'1012' => :'Airport-Link Ferry Service',
102+
:'1013' => :'Car High-Speed Ferry Service',
103+
:'1014' => :'Passenger High-Speed Ferry Service',
104+
:'1015' => :'Sightseeing Boat Service',
105+
:'1016' => :'School Boat',
106+
:'1017' => :'Cable-Drawn Boat Service',
107+
:'1018' => :'River Bus Service',
108+
:'1019' => :'Scheduled Ferry Service',
109+
:'1020' => :'Shuttle Ferry Service',
110+
:'1021' => :'All Water Transport Services',
111+
:'1100' => :'Air Service',
112+
:'1101' => :'International Air Service',
113+
:'1102' => :'Domestic Air Service',
114+
:'1103' => :'Intercontinental Air Service',
115+
:'1104' => :'Domestic Scheduled Air Service',
116+
:'1105' => :'Shuttle Air Service',
117+
:'1106' => :'Intercontinental Charter Air Service',
118+
:'1107' => :'International Charter Air Service',
119+
:'1108' => :'Round-Trip Charter Air Service',
120+
:'1109' => :'Sightseeing Air Service',
121+
:'1110' => :'Helicopter Air Service',
122+
:'1111' => :'Domestic Charter Air Service',
123+
:'1112' => :'Schengen-Area Air Service',
124+
:'1113' => :'Airship Service',
125+
:'1114' => :'All Air Services',
126+
:'1200' => :'Ferry Service',
127+
:'1300' => :'Telecabin Service',
128+
:'1301' => :'Telecabin Service',
129+
:'1302' => :'Cable Car Service',
130+
:'1303' => :'Elevator Service',
131+
:'1304' => :'Chair Lift Service',
132+
:'1305' => :'Drag Lift Service',
133+
:'1306' => :'Small Telecabin Service',
134+
:'1307' => :'All Telecabin Services',
135+
:'1400' => :'Funicular Service',
136+
:'1401' => :'Funicular Service',
137+
:'1402' => :'All Funicular Service',
138+
:'1500' => :'Taxi Service',
139+
:'1501' => :'Communal Taxi Service',
140+
:'1502' => :'Water Taxi Service',
141+
:'1503' => :'Rail Taxi Service',
142+
:'1504' => :'Bike Taxi Service',
143+
:'1505' => :'Licensed Taxi Service',
144+
:'1506' => :'Private Hire Service Vehicle',
145+
:'1507' => :'All Taxi Services',
146+
:'1600' => :'Self Drive',
147+
:'1601' => :'Hire Car',
148+
:'1602' => :'Hire Van',
149+
:'1603' => :'Hire Motorbike',
150+
:'1604' => :'Hire Cycle',
151+
:'1700' => :'Miscellaneous Service',
152+
:'1701' => :'Cable Car',
153+
:'1702' => :'Horse-drawn Carriage'
154+
}
155+
156+
def gtfs_vehicle_type
157+
VEHICLE_TYPES[self.route_type.to_s.to_sym]
158+
end
159+
13160
def id
14161
self.route_id
15162
end

spec/gtfs/route_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,23 @@
1111

1212
include_examples 'models'
1313
end
14+
15+
context 'GTFS::Route.gtfs_vehicle_type' do
16+
it 'returns vehicle_type from string' do
17+
route = GTFS::Route.new({route_type: '0'})
18+
route.gtfs_vehicle_type.should eq(:Tram)
19+
end
20+
it 'returns vehicle_type from symbol' do
21+
route = GTFS::Route.new({route_type: :'0'})
22+
route.gtfs_vehicle_type.should eq(:Tram)
23+
end
24+
it 'returns vehicle_type from integer' do
25+
route = GTFS::Route.new({route_type: 0})
26+
route.gtfs_vehicle_type.should eq(:Tram)
27+
end
28+
it 'supports extended vehicle_types' do
29+
route = GTFS::Route.new({route_type: 100})
30+
route.gtfs_vehicle_type.should eq(:'Railway Service')
31+
end
32+
end
1433
end

0 commit comments

Comments
 (0)