national-rail 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/national-rail/journey_planner.rb +8 -8
- metadata +21 -7
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'mechanize'
|
2
|
-
require '
|
2
|
+
require 'nokogiri'
|
3
3
|
require 'active_support'
|
4
4
|
require 'tidy_ffi'
|
5
5
|
|
@@ -7,10 +7,10 @@ module NationalRail
|
|
7
7
|
|
8
8
|
class JourneyPlanner
|
9
9
|
|
10
|
-
class
|
10
|
+
class NokogiriParser < Mechanize::Page
|
11
11
|
attr_reader :doc
|
12
12
|
def initialize(uri = nil, response = nil, body = nil, code = nil)
|
13
|
-
@doc =
|
13
|
+
@doc = Nokogiri(TidyFFI::Tidy.new(body).clean)
|
14
14
|
super(uri, response, body, code)
|
15
15
|
end
|
16
16
|
end
|
@@ -52,7 +52,7 @@ module NationalRail
|
|
52
52
|
|
53
53
|
def parse_details(page, date)
|
54
54
|
details = {}
|
55
|
-
description = (page.doc/"table#journeyLegDetails tbody tr.lastRow td[@colspan=6] div").last.inner_text.gsub(/\s+/, " ").strip
|
55
|
+
description = (page.doc/"table#journeyLegDetails tbody tr.lastRow td[@colspan='6'] div").last.inner_text.gsub(/\s+/, " ").strip
|
56
56
|
company = (/(.*) service from .* to .*/.match(description)[1]).strip
|
57
57
|
details[:company] = company
|
58
58
|
origins, destinations = (/.* service from (.*) to (.*)/.match(description)[1,2]).map{ |s| s.split(",").map(&:strip) }
|
@@ -99,7 +99,7 @@ module NationalRail
|
|
99
99
|
def initialize
|
100
100
|
Time.zone ||= 'London'
|
101
101
|
@agent = Mechanize.new
|
102
|
-
@agent.pluggable_parser.html =
|
102
|
+
@agent.pluggable_parser.html = NokogiriParser
|
103
103
|
@agent.user_agent_alias = "Mac FireFox"
|
104
104
|
end
|
105
105
|
|
@@ -136,9 +136,9 @@ module NationalRail
|
|
136
136
|
raise (times_page.doc/".error-message").first.inner_text.gsub(/\s+/, " ").strip
|
137
137
|
end
|
138
138
|
|
139
|
-
date = Date.parse((times_page.doc/".journey-details span
|
139
|
+
date = Date.parse((times_page.doc/".journey-details span td").first.children.first.inner_text.gsub(/\s+/, " ").gsub(/\+ 1 day/, '').strip)
|
140
140
|
|
141
|
-
(times_page.doc/"table#outboundJourneyTable > tbody > tr
|
141
|
+
(times_page.doc/"table#outboundJourneyTable > tbody > tr").reject { |tr| %w(status changes).include?(tr.attributes["class"].value) }.each do |tr|
|
142
142
|
|
143
143
|
if (tr.attributes["class"] == "day-heading")
|
144
144
|
date = Date.parse((tr/"th > p > span").first.inner_text.strip)
|
@@ -156,7 +156,7 @@ module NationalRail
|
|
156
156
|
summary_rows
|
157
157
|
rescue => e
|
158
158
|
filename = File.join(File.dirname(__FILE__), "..", "..", "summary-error.html")
|
159
|
-
File.open(filename, "w") { |f| f.write(@agent.current_page.parser.to_html) }
|
159
|
+
File.open(filename, "w") { |f| f.write(TidyFFI::Tidy.new(@agent.current_page.parser.to_html).clean) }
|
160
160
|
raise e
|
161
161
|
end
|
162
162
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 5
|
9
|
+
version: 0.3.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- James Mead
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-17 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -46,9 +46,23 @@ dependencies:
|
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: nokogiri
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 4
|
58
|
+
- 4
|
59
|
+
version: 1.4.4
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activesupport
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
66
|
requirements:
|
53
67
|
- - ~>
|
54
68
|
- !ruby/object:Gem::Version
|
@@ -58,11 +72,11 @@ dependencies:
|
|
58
72
|
- 0
|
59
73
|
version: 3.0.0
|
60
74
|
type: :runtime
|
61
|
-
version_requirements: *
|
75
|
+
version_requirements: *id004
|
62
76
|
- !ruby/object:Gem::Dependency
|
63
77
|
name: tidy_ffi
|
64
78
|
prerelease: false
|
65
|
-
requirement: &
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
66
80
|
requirements:
|
67
81
|
- - ~>
|
68
82
|
- !ruby/object:Gem::Version
|
@@ -72,7 +86,7 @@ dependencies:
|
|
72
86
|
- 3
|
73
87
|
version: 0.1.3
|
74
88
|
type: :runtime
|
75
|
-
version_requirements: *
|
89
|
+
version_requirements: *id005
|
76
90
|
description:
|
77
91
|
email: james@floehopper.org
|
78
92
|
executables: []
|