kalv-tfl-tube-stations 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,46 @@
1
+ TFL Tube Stations
2
+ =================
3
+
4
+ TFL Tube Stations is a gem to help access the TFL tube locations feed
5
+ * It parses the feed
6
+ * Provides objects to play with
7
+
8
+ The data is provided by Tfl as an xml feed. It has all the London Tube stations in it.
9
+
10
+ Beta
11
+ -----
12
+ Currently this is beta and is being worked on, has rspec tests for everything written at this stage
13
+
14
+ Installing
15
+ ----------
16
+ If you haven't already:
17
+ gem sources -a http://gems.github.com
18
+ Then:
19
+ sudo gem install kalv-tfl-tube-stations
20
+
21
+ Testing
22
+ -------
23
+ Uses rspec and fakeweb
24
+ rake spec
25
+
26
+ Usage Examples:
27
+ ---------------
28
+ require 'tfl_tube_stations'
29
+
30
+ TflTubeStations::feed_url = "http://www.tfl.gov.uk/feed_url" # provided by TFL
31
+
32
+ stations = TflTubeStations.get_stations
33
+
34
+ stations.each do |station|
35
+ puts "#{station.name} #{station.address} #{station.coordinates}"
36
+ station.entrances.each do |e|
37
+ puts "#{e.name} #{e.entry_to_bookinghall}"
38
+ puts "#{e.booking_hall_to_platforms.inspect}"
39
+ puts "#{e.platform_to_trains.inspect}"
40
+ end
41
+ end
42
+
43
+
44
+ TODO:
45
+ -----
46
+ - Pull more relevant information from the stations and entrances, currently pulling what's needed for the project I'm working on
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ %w[rubygems rake rake/clean].each { |f| require f }
2
+
3
+ # add jeweler to install gem
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "tfl-tube-stations"
8
+ gemspec.summary = "TFL Tube Stations Feed Library"
9
+ gemspec.description = "A gem to easily connect to the TFL feed of Tube locations and parse the response"
10
+ gemspec.email = "kalv@kalv.co.uk"
11
+ gemspec.homepage = "http://github.com/kalv/tfl-tube-stations"
12
+ gemspec.authors = ["Kalvir Sandhu"]
13
+ gemspec.has_rdoc = false
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ # load other tasks
20
+ Dir['tasks/**/*.rake'].each { |t| load t }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,30 @@
1
+ module TflTubeStations
2
+ class Entrance
3
+
4
+ attr_accessor :doc, :name, :entry_to_bookinghall
5
+
6
+ def initialize(doc)
7
+ @doc = doc
8
+ @name = @doc.search("/name").inner_text
9
+ @entry_to_bookinghall = @doc.search("/entrancetobookinghall").inner_text.strip
10
+ end
11
+
12
+
13
+ def booking_hall_to_platforms
14
+ @booking_hall_to_platforms = []
15
+ @doc.search("/bookingHallToPlatform/path").each do |r|
16
+ @booking_hall_to_platforms << {r.at("/heading").inner_text => r.at("/pathDescription").inner_text}
17
+ end
18
+ @booking_hall_to_platforms
19
+ end
20
+
21
+ def platform_to_trains
22
+ @platform_to_trains = []
23
+ @doc.search("/platformToTrain").each do |r|
24
+ @platform_to_trains << {r.at("/trainName").inner_text => r.at("/platformToTrainSteps").inner_text}
25
+ end
26
+ @platform_to_trains
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ module TflTubeStations
2
+ class Feed
3
+
4
+ attr_accessor :xml, :doc
5
+
6
+ def initialize(url)
7
+ # fetch the url and parse that data
8
+ @xml = Net::HTTP.get(URI.parse(url))
9
+ @doc = Hpricot(@xml)
10
+ end
11
+
12
+ # parse xml feed
13
+ def parse
14
+ # return locations
15
+ stations = @doc.search("//station").collect { |x| Station.new(x) }
16
+
17
+ stations
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module TflTubeStations
2
+ class Station
3
+
4
+ attr_accessor :doc, :name, :address, :entrances, :coordinates
5
+
6
+ def initialize(doc)
7
+ @doc = doc
8
+ @address = @doc.search("/placemark/description").inner_text.strip
9
+ @entrances = @doc.search("/entrances/entrance").collect {|x| Entrance.new(x)}
10
+ @name = @doc.search("/name").inner_text.strip
11
+ @coordinates = @doc.search("/placemark/point/coordinates").inner_text.strip
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ ['feed','station','entrance'].each do |file|
2
+ require File.join(File.dirname(__FILE__), 'tfl_tube_stations', file)
3
+ end
4
+ require 'rubygems'
5
+ require 'net/http'
6
+ require 'hpricot'
7
+
8
+ module TflTubeStations
9
+
10
+ @feed_url = nil # feed location for tfl data
11
+
12
+ def self.get_stations
13
+ return [] if @feed_url.nil?
14
+
15
+ # get feed with the url
16
+ feed = Feed.new(@feed_url)
17
+
18
+ # parse and respond
19
+ feed.parse
20
+ end
21
+
22
+ def self.feed_url=(feed_url)
23
+ @feed_url = feed_url
24
+ end
25
+ end
26
+
27
+ TflTubeStations::feed_url = "http://www.tfl.gov.uk/tfl/businessandpartners/syndication/feed.aspx?email=kalv@kalv.co.uk&feedId=4"
28
+
29
+ stations = TflTubeStations.get_stations
30
+
31
+ stations.each do |station|
32
+ puts "#{station.name} #{station.address}"
33
+ end
data/spec/feed.xml ADDED
@@ -0,0 +1,633 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://www.opengis.net/kml/2.2">
3
+ <Document>
4
+ <name>Transport for London Station Information</name>
5
+ <open>0</open>
6
+ <description>Transport for London Station Information</description>
7
+ <Header>
8
+ <Identifier>TfL | Station information</Identifier>
9
+ <DisplayTitle>TfL | Station information</DisplayTitle>
10
+ <Version>1.0</Version>
11
+ <PublishDateTime canonical="2008-07-31 12:49:08:000">Thu, 31 Jul 2008 12:49:08 +0100</PublishDateTime>
12
+ <Author>webteam@tfl.gov.uk</Author>
13
+ <Owner>Transport for London</Owner>
14
+ <RefreshRate>259200</RefreshRate>
15
+ <Max_Latency>1440</Max_Latency>
16
+ <TimeToError>2880</TimeToError>
17
+ <Schedule>Every quarter</Schedule>
18
+ <OverrideMessage></OverrideMessage>
19
+ <ServiceMessage></ServiceMessage>
20
+ <ErrorMessage></ErrorMessage>
21
+ <FeedInfo></FeedInfo>
22
+ <Attribution>
23
+ <Url>http://www.tfl.gov.uk/</Url>
24
+ <Text>(c) Transport for London</Text>
25
+ <Logo>http://www.tfl.gov.uk/tfl-global/images/roundel.gif</Logo>
26
+ </Attribution>
27
+ <Language>en</Language>
28
+ </Header>
29
+ <stations>
30
+ <station id="1000002" type="tube" xmlns="">
31
+ <name>Acton Town</name>
32
+ <contactDetails>
33
+ <address>Acton Town Station, London Underground Ltd., Gunnersbury Lane, London, W3 8HN</address>
34
+ <phone>0845 330 9875</phone>
35
+ </contactDetails>
36
+ <servingLines>
37
+ <servingLine>District</servingLine>
38
+ <servingLine>Piccadilly</servingLine>
39
+ </servingLines>
40
+ <zones>
41
+ <zone>3</zone>
42
+ </zones>
43
+ <facilities>
44
+ <facility name="Ticket Halls">1</facility>
45
+ <facility name="Lifts">0</facility>
46
+ <facility name="Escalators">0</facility>
47
+ <facility name="Gates">4</facility>
48
+ <facility name="Toilets">yes</facility>
49
+ <facility name="Photo Booths">2</facility>
50
+ <facility name="Cash Machines">2</facility>
51
+ <facility name="Payphones">4</facility>
52
+ <facility name="Car park">no</facility>
53
+ <facility name="Vending Machines">4 snack, 0 drink</facility>
54
+ <facility name="Help Points">0 on platforms, 0 in ticket halls, 0 elsewhere</facility>
55
+ <facility name="Bridge">yes</facility>
56
+ <facility name="Waiting Room">yes</facility>
57
+ <facility name="Other Facilities">subway to street.</facility>
58
+ </facilities>
59
+ <entrances xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
60
+ <entrance>
61
+ <name>Gunnersbury Lane</name>
62
+ <entranceToBookingHall>Level</entranceToBookingHall>
63
+ <bookingHallToPlatform>
64
+ <path>
65
+ <heading>EASTBOUND</heading>
66
+ <pathDescription>14, 14 stairs down</pathDescription>
67
+ </path>
68
+ <path>
69
+ <heading>WESTBOUND</heading>
70
+ <pathDescription>14,14 stairs down</pathDescription>
71
+ </path>
72
+ </bookingHallToPlatform>
73
+ <platformToTrain>
74
+ <trainName>District</trainName>
75
+ <platformToTrainSteps>LEVEL_300</platformToTrainSteps>
76
+ </platformToTrain>
77
+ <platformToTrain>
78
+ <trainName>Piccadilly </trainName>
79
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
80
+ </platformToTrain>
81
+ </entrance>
82
+ </entrances>
83
+ <openingHours>
84
+ <openingHour>
85
+ <entrance>Main entrance: </entrance>
86
+ <timeIntervals type="Mon-Fri">
87
+ <timeInterval>
88
+ <from>05:30</from>
89
+ <to>21:30</to>
90
+ </timeInterval>
91
+ </timeIntervals>
92
+ <timeIntervals type="Sat">
93
+ <timeInterval>
94
+ <from>06:00</from>
95
+ <to>21:30</to>
96
+ </timeInterval>
97
+ </timeIntervals>
98
+ <timeIntervals type="Sun">
99
+ <timeInterval>
100
+ <from>07:00</from>
101
+ <to>23:00</to>
102
+ </timeInterval>
103
+ </timeIntervals>
104
+ </openingHour>
105
+ </openingHours>
106
+ <Placemark>
107
+ <name>Acton Town Station
108
+ </name>
109
+ <description>Acton Town Station, London Underground Ltd., Gunnersbury Lane, London, W3 8HN</description>
110
+ <Point>
111
+ <coordinates>-.280251203536110600,51.502749773000570000,0
112
+ </coordinates>
113
+ </Point>
114
+ </Placemark>
115
+ </station>
116
+ <station id="1000003" type="tube" xmlns="">
117
+ <name>Aldgate</name>
118
+ <contactDetails>
119
+ <address>Aldgate Station, London Underground Ltd., Aldgate High St, London, EC3N 1AH</address>
120
+ <phone>0845 330 9878</phone>
121
+ </contactDetails>
122
+ <servingLines>
123
+ <servingLine>Circle</servingLine>
124
+ <servingLine>Hammersmith &amp; City</servingLine>
125
+ <servingLine>Metropolitan</servingLine>
126
+ </servingLines>
127
+ <zones>
128
+ <zone>1</zone>
129
+ </zones>
130
+ <facilities>
131
+ <facility name="Ticket Halls">1</facility>
132
+ <facility name="Lifts">0</facility>
133
+ <facility name="Escalators">0</facility>
134
+ <facility name="Gates">6</facility>
135
+ <facility name="Toilets">no</facility>
136
+ <facility name="Photo Booths">0</facility>
137
+ <facility name="Cash Machines">0</facility>
138
+ <facility name="Payphones">3</facility>
139
+ <facility name="Car park">no</facility>
140
+ <facility name="Vending Machines">4</facility>
141
+ <facility name="Help Points">0 on platforms, 0 in ticket halls, 0 elsewhere</facility>
142
+ <facility name="Bridge">no</facility>
143
+ <facility name="Waiting Room">yes</facility>
144
+ <facility name="Other Facilities">electronic whiteboards in ticket hall.</facility>
145
+ </facilities>
146
+ <entrances xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
147
+ <entrance>
148
+ <name>Aldgate High Street</name>
149
+ <entranceToBookingHall>Level</entranceToBookingHall>
150
+ <bookingHallToPlatform>
151
+ <pointName/>
152
+ <pathDescription> 16, 10, 14 stairs down</pathDescription>
153
+ </bookingHallToPlatform>
154
+ <platformToTrain>
155
+ <trainName>Metropolitan</trainName>
156
+ <platformToTrainSteps>LEVEL_200</platformToTrainSteps>
157
+ </platformToTrain>
158
+ <platformToTrain>
159
+ <trainName>Circle</trainName>
160
+ <platformToTrainSteps>LEVEL_200</platformToTrainSteps>
161
+ </platformToTrain>
162
+ </entrance>
163
+ </entrances>
164
+ <openingHours>
165
+ <openingHour>
166
+ <entrance>Northern</entrance>
167
+ <timeIntervals type="Mon-Fri">
168
+ <timeInterval>
169
+ <from>07:00</from>
170
+ <to>10:00</to>
171
+ </timeInterval>
172
+ <timeInterval>
173
+ <from>15:30</from>
174
+ <to>19:00</to>
175
+ </timeInterval>
176
+ </timeIntervals>
177
+ </openingHour>
178
+ </openingHours>
179
+ <Placemark>
180
+ <name>Aldgate Station
181
+ </name>
182
+ <description>Aldgate Station, London Underground Ltd., Aldgate High St, London, EC3N 1AH</description>
183
+ <Point>
184
+ <coordinates>-.075614184477749600,51.514271823083390000,0
185
+ </coordinates>
186
+ </Point>
187
+ </Placemark>
188
+ </station>
189
+ <station id="1000004" type="tube" xmlns="">
190
+ <name>Aldgate East</name>
191
+ <contactDetails>
192
+ <address>Aldgate East Station, London Underground Ltd., Whitechapel High St, London, E1 7PT</address>
193
+ <phone>0845 330 9878</phone>
194
+ </contactDetails>
195
+ <servingLines>
196
+ <servingLine>Circle</servingLine>
197
+ <servingLine>District</servingLine>
198
+ <servingLine>Hammersmith &amp; City</servingLine>
199
+ </servingLines>
200
+ <zones>
201
+ <zone>1</zone>
202
+ </zones>
203
+ <facilities>
204
+ <facility name="Ticket Halls">2</facility>
205
+ <facility name="Lifts">0</facility>
206
+ <facility name="Escalators">0</facility>
207
+ <facility name="Gates">9</facility>
208
+ <facility name="Toilets">no</facility>
209
+ <facility name="Photo Booths">1</facility>
210
+ <facility name="Cash Machines">2</facility>
211
+ <facility name="Payphones">8</facility>
212
+ <facility name="Car park">no</facility>
213
+ <facility name="Vending Machines">7</facility>
214
+ <facility name="Help Points">0 on platforms, 0 in ticket halls, 0 elsewhere</facility>
215
+ <facility name="Bridge">yes</facility>
216
+ <facility name="Waiting Room">yes</facility>
217
+ <facility name="Other Facilities">
218
+ </facility>
219
+ </facilities>
220
+ <entrances xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
221
+ <entrance>
222
+ <name>Whitechapel High Street (North Side) and Commercial Street (West Side)</name>
223
+ <entranceToBookingHall> 13, 13 stairs down</entranceToBookingHall>
224
+ <bookingHallToPlatform>
225
+ <pointName/>
226
+ <pathDescription>9, 13 stairs down</pathDescription>
227
+ </bookingHallToPlatform>
228
+ <platformToTrain>
229
+ <trainName>District </trainName>
230
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
231
+ </platformToTrain>
232
+ <platformToTrain>
233
+ <trainName> Hammersmith &amp; City</trainName>
234
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
235
+ </platformToTrain>
236
+ </entrance>
237
+ <entrance>
238
+ <name>Leman Street (West) (Colchester Street)</name>
239
+ <entranceToBookingHall>16, 6, 4 stairs down</entranceToBookingHall>
240
+ <bookingHallToPlatform>
241
+ <pointName/>
242
+ <pathDescription> 9, 13 stairs down</pathDescription>
243
+ </bookingHallToPlatform>
244
+ <platformToTrain>
245
+ <trainName>District </trainName>
246
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
247
+ </platformToTrain>
248
+ <platformToTrain>
249
+ <trainName> Hammersmith &amp; City</trainName>
250
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
251
+ </platformToTrain>
252
+ </entrance>
253
+ <entrance>
254
+ <name>Whitechapel High Street (South Side) and Leman Street (East Side)</name>
255
+ <entranceToBookingHall> 12, 12 stairs down, subway, 4 stairs down</entranceToBookingHall>
256
+ <bookingHallToPlatform>
257
+ <pointName/>
258
+ <pathDescription>9, 1 stairs down</pathDescription>
259
+ </bookingHallToPlatform>
260
+ <platformToTrain>
261
+ <trainName>District </trainName>
262
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
263
+ </platformToTrain>
264
+ <platformToTrain>
265
+ <trainName> Hammersmith &amp; City</trainName>
266
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
267
+ </platformToTrain>
268
+ </entrance>
269
+ <entrance>
270
+ <name>Leman Street (East) (Colchester Street)</name>
271
+ <entranceToBookingHall>Ramp down, subway, 4 stairs down</entranceToBookingHall>
272
+ <bookingHallToPlatform>
273
+ <pointName/>
274
+ <pathDescription> 9, 13 stairs down</pathDescription>
275
+ </bookingHallToPlatform>
276
+ <platformToTrain>
277
+ <trainName>District </trainName>
278
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
279
+ </platformToTrain>
280
+ <platformToTrain>
281
+ <trainName> Hammersmith &amp; City</trainName>
282
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
283
+ </platformToTrain>
284
+ </entrance>
285
+ <entrance>
286
+ <name>Braham Street (South Side)</name>
287
+ <entranceToBookingHall> 15 stairs down, subway, 4 stairs down</entranceToBookingHall>
288
+ <bookingHallToPlatform>
289
+ <pointName/>
290
+ <pathDescription> 9, 13 stairs down</pathDescription>
291
+ </bookingHallToPlatform>
292
+ <platformToTrain>
293
+ <trainName>District</trainName>
294
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
295
+ </platformToTrain>
296
+ <platformToTrain>
297
+ <trainName> Hammersmith &amp; City</trainName>
298
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
299
+ </platformToTrain>
300
+ </entrance>
301
+ <entrance>
302
+ <name>Braham Street (North Side) and Drum Street</name>
303
+ <entranceToBookingHall> Ramp down, subway, 4 stairs down</entranceToBookingHall>
304
+ <bookingHallToPlatform>
305
+ <pointName/>
306
+ <pathDescription> 9, 13 stairs down</pathDescription>
307
+ </bookingHallToPlatform>
308
+ <platformToTrain>
309
+ <trainName>District</trainName>
310
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
311
+ </platformToTrain>
312
+ <platformToTrain>
313
+ <trainName> Hammersmith &amp; City</trainName>
314
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
315
+ </platformToTrain>
316
+ </entrance>
317
+ <entrance>
318
+ <name>Whitechapel High Street (South Side) and Braham Street (North Side)</name>
319
+ <entranceToBookingHall> Ramp down, or 13, 12 stairs down, then subway, 6 stairs down</entranceToBookingHall>
320
+ <bookingHallToPlatform>
321
+ <pointName/>
322
+ <pathDescription>11, 11 stairs down</pathDescription>
323
+ </bookingHallToPlatform>
324
+ <platformToTrain>
325
+ <trainName>District </trainName>
326
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
327
+ </platformToTrain>
328
+ <platformToTrain>
329
+ <trainName> Hammersmith &amp; City</trainName>
330
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
331
+ </platformToTrain>
332
+ </entrance>
333
+ <entrance>
334
+ <name>Commercial Road (North Side) and Manningtree Street</name>
335
+ <entranceToBookingHall> Ramp down, or 12, 13 stairs down, then subway, 6 stairs down</entranceToBookingHall>
336
+ <bookingHallToPlatform>
337
+ <pointName/>
338
+ <pathDescription> 11, 11 stairs down</pathDescription>
339
+ </bookingHallToPlatform>
340
+ <platformToTrain>
341
+ <trainName>District</trainName>
342
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
343
+ </platformToTrain>
344
+ <platformToTrain>
345
+ <trainName> Hammersmith &amp; City</trainName>
346
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
347
+ </platformToTrain>
348
+ </entrance>
349
+ <entrance>
350
+ <name>Whitechapel High Street (South Side)</name>
351
+ <entranceToBookingHall> Ramp down or 11, 11 stairs down then 6 stairs down</entranceToBookingHall>
352
+ <bookingHallToPlatform>
353
+ <pointName/>
354
+ <pathDescription>11, 11 stairs down</pathDescription>
355
+ </bookingHallToPlatform>
356
+ <platformToTrain>
357
+ <trainName>District </trainName>
358
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
359
+ </platformToTrain>
360
+ <platformToTrain>
361
+ <trainName> Hammersmith &amp; City</trainName>
362
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
363
+ </platformToTrain>
364
+ </entrance>
365
+ <entrance>
366
+ <name>Whitechapel High Street (North Side)</name>
367
+ <entranceToBookingHall> 15, 5, 5 stairs down</entranceToBookingHall>
368
+ <bookingHallToPlatform>
369
+ <pointName/>
370
+ <pathDescription> 11, 11 stairs down</pathDescription>
371
+ </bookingHallToPlatform>
372
+ <platformToTrain>
373
+ <trainName>District</trainName>
374
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
375
+ </platformToTrain>
376
+ <platformToTrain>
377
+ <trainName> Hammersmith &amp; City</trainName>
378
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
379
+ </platformToTrain>
380
+ </entrance>
381
+ </entrances>
382
+ <openingHours>
383
+ <openingHour>
384
+ <entrance>Gallery (East)</entrance>
385
+ <timeIntervals type="Mon-Fri">
386
+ <timeInterval>
387
+ <from>08:00</from>
388
+ <to>19:00</to>
389
+ </timeInterval>
390
+ </timeIntervals>
391
+ <timeIntervals type="Sat">
392
+ <timeInterval>
393
+ <from>09:00</from>
394
+ <to>13:30</to>
395
+ </timeInterval>
396
+ </timeIntervals>
397
+ </openingHour>
398
+ <openingHour>
399
+ <entrance>Main (West)</entrance>
400
+ <timeIntervals type="Mon-Fri">
401
+ <timeInterval>
402
+ <from>06:30</from>
403
+ <to>19:30</to>
404
+ </timeInterval>
405
+ </timeIntervals>
406
+ <timeIntervals type="Sat">
407
+ <timeInterval>
408
+ <from>08:30</from>
409
+ <to>20:30</to>
410
+ </timeInterval>
411
+ </timeIntervals>
412
+ <timeIntervals type="Sun">
413
+ <timeInterval>
414
+ <from>08:30</from>
415
+ <to>20:00</to>
416
+ </timeInterval>
417
+ </timeIntervals>
418
+ </openingHour>
419
+ </openingHours>
420
+ <Placemark>
421
+ <name>Aldgate East Station
422
+ </name>
423
+ <description>Aldgate East Station, London Underground Ltd., Whitechapel High St, London, E1 7PT</description>
424
+ <Point>
425
+ <coordinates>-.072287119975365420,51.515233413796480000,0
426
+ </coordinates>
427
+ </Point>
428
+ </Placemark>
429
+ </station>
430
+ <station id="1000005" type="tube" xmlns="">
431
+ <name>Alperton</name>
432
+ <contactDetails>
433
+ <address>Alperton Station, London Underground Ltd., Ealing Rd, Wembley, Middlesex, HA0 4LL</address>
434
+ <phone>0845 330 9875</phone>
435
+ </contactDetails>
436
+ <servingLines>
437
+ <servingLine>Piccadilly</servingLine>
438
+ </servingLines>
439
+ <zones>
440
+ <zone>4</zone>
441
+ </zones>
442
+ <facilities>
443
+ <facility name="Ticket Halls">1</facility>
444
+ <facility name="Lifts">0</facility>
445
+ <facility name="Escalators">0</facility>
446
+ <facility name="Gates">3</facility>
447
+ <facility name="Toilets">yes</facility>
448
+ <facility name="Photo Booths">1</facility>
449
+ <facility name="Cash Machines">0</facility>
450
+ <facility name="Payphones">2</facility>
451
+ <facility name="Car park">no</facility>
452
+ <facility name="Vending Machines">2 snack, 1 drink</facility>
453
+ <facility name="Help Points">0 on platforms, 0 in ticket halls, 0 elsewhere</facility>
454
+ <facility name="Bridge">yes</facility>
455
+ <facility name="Waiting Room">yes</facility>
456
+ <facility name="Other Facilities"></facility>
457
+ </facilities>
458
+ <entrances xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
459
+ <entrance>
460
+ <name>Ealing Road</name>
461
+ <entranceToBookingHall> Level</entranceToBookingHall>
462
+ <bookingHallToPlatform>
463
+ <pointName/>
464
+ <pathDescription> 3 x 14 stairs up</pathDescription>
465
+ </bookingHallToPlatform>
466
+ <platformToTrain>
467
+ <trainName>Piccadilly</trainName>
468
+ <platformToTrainSteps>LEVEL_100</platformToTrainSteps>
469
+ </platformToTrain>
470
+ </entrance>
471
+ </entrances>
472
+ <openingHours>
473
+ <openingHour>
474
+ <entrance>Main entrance: </entrance>
475
+ <timeIntervals type="Mon-Fri">
476
+ <timeInterval>
477
+ <from>06:30</from>
478
+ <to>14:00</to>
479
+ </timeInterval>
480
+ <timeInterval>
481
+ <from>15:30</from>
482
+ <to>20:00</to>
483
+ </timeInterval>
484
+ </timeIntervals>
485
+ <timeIntervals type="Sat">
486
+ <timeInterval>
487
+ <from>07:30</from>
488
+ <to>18:30</to>
489
+ </timeInterval>
490
+ </timeIntervals>
491
+ <timeIntervals type="Sun">
492
+ <timeInterval>
493
+ <from>09:00</from>
494
+ <to>21:00</to>
495
+ </timeInterval>
496
+ </timeIntervals>
497
+ </openingHour>
498
+ </openingHours>
499
+ <Placemark>
500
+ <name>Alperton Station
501
+ </name>
502
+ <description>Alperton Station, London Underground Ltd., Ealing Rd, Wembley, Middlesex, HA0 4LL</description>
503
+ <Point>
504
+ <coordinates>-.299486538678611470,51.540694766293470000,0
505
+ </coordinates>
506
+ </Point>
507
+ </Placemark>
508
+ </station>
509
+ <station id="1000006" type="tube" xmlns="">
510
+ <name>Amersham</name>
511
+ <contactDetails>
512
+ <address>Amersham Station, Stn Approach, Amersham, Bucks HP6 5AZ</address>
513
+ <phone>0845 330 9878</phone>
514
+ </contactDetails>
515
+ <servingLines>
516
+ <servingLine>Metropolitan</servingLine>
517
+ </servingLines>
518
+ <zones>
519
+ <zone>6d</zone>
520
+ </zones>
521
+ <facilities>
522
+ <facility name="Ticket Halls">1</facility>
523
+ <facility name="Lifts">0</facility>
524
+ <facility name="Escalators">0</facility>
525
+ <facility name="Gates">4</facility>
526
+ <facility name="Toilets">yes</facility>
527
+ <facility name="Photo Booths">1</facility>
528
+ <facility name="Cash Machines">0</facility>
529
+ <facility name="Payphones">3</facility>
530
+ <facility name="Car park">yes</facility>
531
+ <facility name="Vending Machines">1</facility>
532
+ <facility name="Help Points">2 on platforms, 0 in ticket halls, 0 elsewhere</facility>
533
+ <facility name="Bridge">no</facility>
534
+ <facility name="Waiting Room">yes</facility>
535
+ <facility name="Other Facilities">post office style queuing for tickets.</facility>
536
+ </facilities>
537
+ <entrances xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
538
+ <entrance>
539
+ <name>Chiltern Avenue</name>
540
+ <entranceToBookingHall>Level</entranceToBookingHall>
541
+ <bookingHallToPlatform>
542
+ <path>
543
+ <heading>NORTHBOUND</heading>
544
+ <pathDescription>Level (except certain trains)</pathDescription>
545
+ </path>
546
+ <path>
547
+ <heading>NORTHBOUND</heading>
548
+ <pathDescription>14, 9 stairs up, footbridge, 9, 14 stairs down</pathDescription>
549
+ </path>
550
+ </bookingHallToPlatform>
551
+ <platformToTrain>
552
+ <trainName>Metropolitan</trainName>
553
+ <platformToTrainSteps>LEVEL_200</platformToTrainSteps>
554
+ </platformToTrain>
555
+ </entrance>
556
+ </entrances>
557
+ <openingHours>
558
+ <openingHour>
559
+ <entrance>Main entrance: </entrance>
560
+ <timeIntervals type="Mon-Fri">
561
+ <timeInterval>
562
+ <from>06:00</from>
563
+ <to>19:00</to>
564
+ </timeInterval>
565
+ </timeIntervals>
566
+ <timeIntervals type="Sat">
567
+ <timeInterval>
568
+ <from>07:30</from>
569
+ <to>18:00</to>
570
+ </timeInterval>
571
+ </timeIntervals>
572
+ <timeIntervals type="Sun">
573
+ <timeInterval>
574
+ <from>08:30</from>
575
+ <to>18:00</to>
576
+ </timeInterval>
577
+ </timeIntervals>
578
+ </openingHour>
579
+ </openingHours>
580
+ <Placemark>
581
+ <name>Amersham Station
582
+ </name>
583
+ <description>Amersham Station, Stn Approach, Amersham, Bucks HP6 5AZ</description>
584
+ <Point>
585
+ <coordinates>-.607478839102469000,51.674149710629730000,0
586
+ </coordinates>
587
+ </Point>
588
+ </Placemark>
589
+ </station>
590
+
591
+ </stations>
592
+ <lines>
593
+ <line>
594
+ <Style id="yellowLineGreenPoly">
595
+ <LineStyle>
596
+ <color>7f00ffff</color>
597
+ <width>4</width>
598
+ </LineStyle>
599
+ <PolyStyle>
600
+ <color>7f00ff00</color>
601
+ </PolyStyle>
602
+ </Style>
603
+ <Placemark>
604
+ <name>
605
+ Circle Line
606
+ </name>
607
+ <description>
608
+ London Underground Circle Line
609
+ </description>
610
+ <styleUrl>#yellowLineGreenPoly</styleUrl>
611
+ <LineString>
612
+ <extrude>1</extrude>
613
+ <tessellate>1</tessellate>
614
+ <altitudeMode>absolute</altitudeMode>
615
+ <coordinates>
616
+ -.075614184477749600,51.514271823083390000,0
617
+ -.072287119975365420,51.515233413796480000,0
618
+ -.156900356057780880,51.523061248142790000,0
619
+ -.088915809045260000,51.513302371519344000,0
620
+ -.097711123216248310,51.520145725324900000,0
621
+ .080863182849410430,51.539451208515715000,0
622
+ -.188038262221618460,51.512233058741060000,0
623
+ -.103606731219862620,51.511490522247490000,0
624
+ -.024823746874528683,51.526800254826064000,0
625
+ -.090694850680980680,51.511433722337300000,0
626
+ -.122360215814178660,51.507241796748396000,0
627
+ </coordinates>
628
+ </LineString>
629
+ </Placemark>
630
+ </line>
631
+ </lines>
632
+ </Document>
633
+ </kml>
data/spec/feed_spec.rb ADDED
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Feed" do
4
+
5
+ before(:each) do
6
+ @url = "http://test/feed"
7
+ # set up fakeweb
8
+ FakeWeb.register_uri(:get, @url, :body => File.expand_path('spec/feed.xml'))
9
+
10
+ @feed = TflTubeStations::Feed.new(@url)
11
+ end
12
+
13
+ it "should pull the feed" do
14
+ @feed.xml.should_not be_nil
15
+ end
16
+
17
+ it "should create an xml doc" do
18
+ @feed.doc.should_not be_nil
19
+ @feed.doc.search("//station").size.should > 0
20
+ end
21
+
22
+ # it "should error gracefully" do
23
+ # FakeWeb.register_uri(:get, @url, :body => "Nothing to be found 'round here",
24
+ # :status => ["404", "Not Found"])
25
+ # false.should == true
26
+ # end
27
+
28
+ describe "Parsing" do
29
+
30
+ before(:each) do
31
+ @stations = @feed.parse
32
+ end
33
+
34
+ it "should parse the feed and return stations" do
35
+ @stations.size.should == 5
36
+ end
37
+
38
+ it "should return instances of Station" do
39
+ @stations[0].should be_an_instance_of TflTubeStations::Station
40
+ end
41
+
42
+ it "should hold station name" do
43
+ @stations[0].name.should == "Acton Town"
44
+ end
45
+
46
+ it "should hold station address" do
47
+ @stations[0].address.should == "Acton Town Station, London Underground Ltd., Gunnersbury Lane, London, W3 8HN"
48
+ end
49
+
50
+ it "should parse the station coordinates" do
51
+ @stations[0].coordinates.should == "-.280251203536110600,51.502749773000570000,0"
52
+ end
53
+
54
+ it "should hold the entrances" do
55
+ @stations[0].entrances.size.should == 1
56
+ @stations[0].entrances[0].should be_an_instance_of TflTubeStations::Entrance
57
+ end
58
+
59
+ it "should have entrance name" do
60
+ @stations[0].entrances[0].name.should_not be_nil
61
+ @stations[0].entrances[0].name.should == "Gunnersbury Lane"
62
+ end
63
+
64
+ it "should have an entrance entry to booking hall" do
65
+ @stations[0].entrances[0].entry_to_bookinghall.should == "Level"
66
+ end
67
+
68
+ it "should have entrance booking_hall_to_platforms" do
69
+ @stations[0].entrances[0].booking_hall_to_platforms.size.should == 2
70
+ @stations[0].entrances[0].booking_hall_to_platforms[0].should == {"EASTBOUND"=>"14, 14 stairs down"}
71
+ end
72
+
73
+ it "should have entrance platform_to_trains" do
74
+ @stations[0].entrances[0].platform_to_trains.size.should == 2
75
+ @stations[0].entrances[0].platform_to_trains[0].should == {"District"=>"LEVEL_300"}
76
+ end
77
+
78
+ end
79
+
80
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'spec'
3
+ require 'fakeweb'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ gem 'rspec'
7
+ require 'spec'
8
+ require 'fakeweb'
9
+ end
10
+
11
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
12
+ require 'tfl_tube_stations'
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "TFL Tube Stations" do
4
+
5
+ it "should return empty when no feed url provided" do
6
+ stations = TflTubeStations.get_stations
7
+ stations.size.should == 0
8
+ end
9
+
10
+ it "should return stations when feed url provided" do
11
+ FakeWeb.register_uri(:get, "http://test/feed", :body => File.expand_path('spec/feed.xml'))
12
+
13
+ TflTubeStations::feed_url = "http://test/feed"
14
+ stations = TflTubeStations.get_stations
15
+ stations.size.should == 5
16
+ stations[0].name.should == "Acton Town"
17
+ end
18
+
19
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'spec'
3
+ require 'fakeweb'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'spec'
7
+ end
8
+ begin
9
+ require 'spec/rake/spectask'
10
+ require 'fakeweb'
11
+ rescue LoadError
12
+ puts <<-EOS
13
+ To use rspec for testing you must install rspec and the fakeweb gem:
14
+ gem install rspec fakeweb
15
+ EOS
16
+ exit(0)
17
+ end
18
+
19
+ desc "Run the specs under spec"
20
+ Spec::Rake::SpecTask.new do |t|
21
+ t.spec_opts = ['--options', "spec/spec.opts"]
22
+ t.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{tfl-tube-stations}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Kalvir Sandhu"]
9
+ s.date = %q{2009-07-30}
10
+ s.description = %q{A gem to easily connect to the TFL feed of Tube locations and parse the response}
11
+ s.email = %q{kalv@kalv.co.uk}
12
+ s.extra_rdoc_files = [
13
+ "README.markdown"
14
+ ]
15
+ s.files = [
16
+ "README.markdown",
17
+ "Rakefile",
18
+ "VERSION",
19
+ "lib/tfl_tube_stations.rb",
20
+ "lib/tfl_tube_stations/entrance.rb",
21
+ "lib/tfl_tube_stations/feed.rb",
22
+ "lib/tfl_tube_stations/station.rb",
23
+ "spec/feed.xml",
24
+ "spec/feed_spec.rb",
25
+ "spec/spec.opts",
26
+ "spec/spec_helper.rb",
27
+ "spec/tfl_tube_stations_spec.rb",
28
+ "tasks/rspec.rake",
29
+ "tfl-tube-stations.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/kalv/tfl-tube-stations}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.2}
35
+ s.summary = %q{TFL Tube Stations Feed Library}
36
+ s.test_files = [
37
+ "spec/feed_spec.rb",
38
+ "spec/spec_helper.rb",
39
+ "spec/tfl_tube_stations_spec.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kalv-tfl-tube-stations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kalvir Sandhu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-30 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A gem to easily connect to the TFL feed of Tube locations and parse the response
17
+ email: kalv@kalv.co.uk
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - README.markdown
26
+ - Rakefile
27
+ - VERSION
28
+ - lib/tfl_tube_stations.rb
29
+ - lib/tfl_tube_stations/entrance.rb
30
+ - lib/tfl_tube_stations/feed.rb
31
+ - lib/tfl_tube_stations/station.rb
32
+ - spec/feed.xml
33
+ - spec/feed_spec.rb
34
+ - spec/spec.opts
35
+ - spec/spec_helper.rb
36
+ - spec/tfl_tube_stations_spec.rb
37
+ - tasks/rspec.rake
38
+ - tfl-tube-stations.gemspec
39
+ has_rdoc: false
40
+ homepage: http://github.com/kalv/tfl-tube-stations
41
+ licenses:
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: TFL Tube Stations Feed Library
66
+ test_files:
67
+ - spec/feed_spec.rb
68
+ - spec/spec_helper.rb
69
+ - spec/tfl_tube_stations_spec.rb