national-rail 0.4.11 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module NationalRail
2
- VERSION = "0.4.11".freeze
2
+ VERSION = "0.4.12".freeze
3
3
  end
@@ -99,31 +99,36 @@ module NationalRail
99
99
  VirginLiveDepartureBoards.capture(page, filename)
100
100
  encoding = 'UTF-8'
101
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|
105
- tds = tr/"td"
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
102
+ if tbody
103
+ trs = tbody/"tr"
104
+ if trs.length > 2
105
+ columns = ((trs[1])/"th").map { |th| th.inner_text.gsub(/\s+/, ' ') }
106
+ summary_rows = []
107
+ ((tbody/"tr")[2..-1] || []).each do |tr|
108
+ tds = tr/"td"
109
+ from = tds[columns.index("From")]
110
+ if from.inner_text.match(/circular route/i)
111
+ summary_rows.last.attributes[:circular_route] = true if summary_rows.any?
112
+ next
113
+ end
114
+ details_href = (from/"a").first["href"]
115
+ details_link = page.links.detect { |l| l.attributes["href"] == details_href }
116
+ attributes = {
117
+ :from => (tds[columns.index("From")]/"a").inner_text.gsub(/\s+/, ' '),
118
+ :timetabled_arrival => time_parser.parse(cell_text(tds[columns.index("Timetabled Arrival")])),
119
+ :expected_arrival => time_parser.parse(cell_text(tds[columns.index("Expected Arrival")])),
120
+ :to => (tds[columns.index("To")]/"a").inner_text.gsub(/\s+/, ' '),
121
+ :timetabled_departure => time_parser.parse(cell_text(tds[columns.index("Timetabled Departure")])),
122
+ :expected_departure => time_parser.parse(cell_text(tds[columns.index("Expected Departure")])),
123
+ :operator => (tds[columns.index("Operator")]/"a").inner_text.gsub(/\s+/, ' '),
124
+ :details_url => "http://realtime.nationalrail.co.uk/virgintrains/#{details_href}"
125
+ }
126
+ if platform_index = columns.index("Platform")
127
+ attributes[:platform] = parse_integer(cell_text(tds[platform_index]))
128
+ end
129
+ summary_rows << SummaryRow.new(@agent, details_link, attributes)
130
+ end
110
131
  end
111
- details_href = (from/"a").first["href"]
112
- details_link = page.links.detect { |l| l.attributes["href"] == details_href }
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+/, ' '),
121
- :details_url => "http://realtime.nationalrail.co.uk/virgintrains/#{details_href}"
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)
127
132
  end
128
133
  end
129
134
  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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 11
10
- version: 0.4.11
9
+ - 12
10
+ version: 0.4.12
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-11 00:00:00 +01:00
18
+ date: 2011-04-12 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency