national-rail 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ require 'national-rail/version'
1
2
  require 'national-rail/journey_planner'
2
3
  require 'national-rail/live_departure_boards'
3
4
  require 'national-rail/station_list'
@@ -0,0 +1,3 @@
1
+ module NationalRail
2
+ VERSION = "0.4.11".freeze
3
+ end
@@ -98,21 +98,32 @@ module NationalRail
98
98
  @agent.get("http://realtime.nationalrail.co.uk/virgintrains/#{filename}") do |page|
99
99
  VirginLiveDepartureBoards.capture(page, filename)
100
100
  encoding = 'UTF-8'
101
- summary_rows = ((page.doc/"table#TrainTable tbody tr")[2..-1] || []).map do |tr|
101
+ tbody = page.doc/"table#TrainTable tbody"
102
+ columns = (((tbody/"tr")[1])/"th").map { |th| th.inner_text.gsub(/\s+/, ' ') }
103
+ summary_rows = []
104
+ ((tbody/"tr")[2..-1] || []).each do |tr|
102
105
  tds = tr/"td"
103
- details_href = (tds[0]/"a").first["href"]
106
+ from = tds[columns.index("From")]
107
+ if from.inner_text.match(/circular route/i)
108
+ summary_rows.last.attributes[:circular_route] = true if summary_rows.any?
109
+ next
110
+ end
111
+ details_href = (from/"a").first["href"]
104
112
  details_link = page.links.detect { |l| l.attributes["href"] == details_href }
105
- SummaryRow.new(@agent, details_link, {
106
- :from => (tds[0]/"a").inner_text.gsub(/\s+/, ' '),
107
- :timetabled_arrival => time_parser.parse(cell_text(tds[1])),
108
- :expected_arrival => time_parser.parse(cell_text(tds[2])),
109
- :platform => parse_integer(cell_text(tds[3])),
110
- :to => (tds[4]/"a").inner_text.gsub(/\s+/, ' '),
111
- :timetabled_departure => time_parser.parse(cell_text(tds[5])),
112
- :expected_departure => time_parser.parse(cell_text(tds[6])),
113
- :operator => (tds[7]/"a").inner_text.gsub(/\s+/, ' '),
113
+ attributes = {
114
+ :from => (tds[columns.index("From")]/"a").inner_text.gsub(/\s+/, ' '),
115
+ :timetabled_arrival => time_parser.parse(cell_text(tds[columns.index("Timetabled Arrival")])),
116
+ :expected_arrival => time_parser.parse(cell_text(tds[columns.index("Expected Arrival")])),
117
+ :to => (tds[columns.index("To")]/"a").inner_text.gsub(/\s+/, ' '),
118
+ :timetabled_departure => time_parser.parse(cell_text(tds[columns.index("Timetabled Departure")])),
119
+ :expected_departure => time_parser.parse(cell_text(tds[columns.index("Expected Departure")])),
120
+ :operator => (tds[columns.index("Operator")]/"a").inner_text.gsub(/\s+/, ' '),
114
121
  :details_url => "http://realtime.nationalrail.co.uk/virgintrains/#{details_href}"
115
- })
122
+ }
123
+ if platform_index = columns.index("Platform")
124
+ attributes[:platform] = parse_integer(cell_text(tds[platform_index]))
125
+ end
126
+ summary_rows << SummaryRow.new(@agent, details_link, attributes)
116
127
  end
117
128
  end
118
129
  summary_rows
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: national-rail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 10
10
- version: 0.4.10
9
+ - 11
10
+ version: 0.4.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Mead
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-01 00:00:00 +01:00
18
+ date: 2011-04-11 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -209,6 +209,7 @@ files:
209
209
  - lib/national-rail/live_departure_boards.rb
210
210
  - lib/national-rail/station_list.rb
211
211
  - lib/national-rail/stations.kml
212
+ - lib/national-rail/version.rb
212
213
  - lib/national-rail/virgin_live_departure_boards.rb
213
214
  - lib/national-rail/virgin_live_departure_boards/details_page_parser.rb
214
215
  has_rdoc: true