tube 0.2.0 → 0.2.1
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.
- data/lib/tube/status.rb +1 -1
- data/lib/tube/status_parser.rb +8 -3
- data/test/dummy.html +1 -1
- data/test/status_parser_test.rb +3 -3
- metadata +2 -2
data/lib/tube/status.rb
CHANGED
@@ -52,7 +52,7 @@ module Tube # :nodoc:
|
|
52
52
|
#
|
53
53
|
def initialize( url=
|
54
54
|
"http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/default.html" )
|
55
|
-
results = Tube::StatusParser.parse( open( url ) )
|
55
|
+
results = Tube::StatusParser.parse( open( url ).read )
|
56
56
|
@updated = results[:updated]
|
57
57
|
|
58
58
|
@lines = results[:lines].map do |line|
|
data/lib/tube/status_parser.rb
CHANGED
@@ -8,6 +8,7 @@ module Tube # :nodoc:
|
|
8
8
|
extend self
|
9
9
|
|
10
10
|
def parse( html_doc )
|
11
|
+
html_doc.gsub!(" ", " ")
|
11
12
|
service_board = Hpricot( html_doc ).at( "#service-board" )
|
12
13
|
|
13
14
|
updated_element = service_board.previous_sibling.children.first
|
@@ -26,7 +27,7 @@ module Tube # :nodoc:
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def parse_updated( updated_element )
|
29
|
-
time_text = updated_element.inner_text.match( /(\d?\d:\d\d
|
30
|
+
time_text = updated_element.inner_text.match( /(\d?\d:\d\d)/ )[0]
|
30
31
|
time_zone = if is_bst? then "+0100" else "+0000" end
|
31
32
|
|
32
33
|
Time.parse( "#{time_text} #{time_zone}" )
|
@@ -99,8 +100,12 @@ module Tube # :nodoc:
|
|
99
100
|
bst_end = last_sunday_of_month( "october" )
|
100
101
|
|
101
102
|
one_hour = 3600
|
102
|
-
|
103
|
-
|
103
|
+
|
104
|
+
bst_start = Time.gm( bst_start.year, bst_start.month, bst_start.day )
|
105
|
+
bst_start += one_hour
|
106
|
+
|
107
|
+
bst_end = Time.gm( bst_end.year, bst_end.month, bst_end.day )
|
108
|
+
bst_end += one_hour
|
104
109
|
|
105
110
|
(bst_start..bst_end).include?( Time.now.getgm )
|
106
111
|
end
|
data/test/dummy.html
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
<div id="main-content">
|
15
15
|
<h1>Live travel news</h1>
|
16
16
|
|
17
|
-
<h2>Service update at 12:
|
17
|
+
<h2>Service update at 12:12 <a href="later.html" id="works_later" class="alert" name="works_later">View engineering works planned for <strong>later today</strong></a></h2>
|
18
18
|
<div id="service-board">
|
19
19
|
<dl id="lines">
|
20
20
|
<dt class="central">Central</dt>
|
data/test/status_parser_test.rb
CHANGED
@@ -4,7 +4,7 @@ require "#{File.dirname( __FILE__ )}/../lib/tube/status"
|
|
4
4
|
|
5
5
|
class TestStatusParser < Test::Unit::TestCase
|
6
6
|
def test_parse_updated
|
7
|
-
document = Hpricot("<h2>Service update at
|
7
|
+
document = Hpricot("<h2>Service update at 18:26</h2>")
|
8
8
|
element = document.at("h2")
|
9
9
|
result = Tube::StatusParser.parse_updated(element)
|
10
10
|
|
@@ -12,7 +12,7 @@ class TestStatusParser < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_parse_updated_with_anchor_in_element
|
15
|
-
document = Hpricot(%Q{<h2>Service update at 12:
|
15
|
+
document = Hpricot(%Q{<h2>Service update at 12:12 <a href="/later.html">View engineering works planned for later today</a></h2>})
|
16
16
|
element = document.at("h2")
|
17
17
|
result = Tube::StatusParser.parse_updated(element)
|
18
18
|
|
@@ -121,7 +121,7 @@ class TestStatusParser < Test::Unit::TestCase
|
|
121
121
|
def test_parse
|
122
122
|
# the file used here is an approximation of the most important bits of the
|
123
123
|
# Live travel news at http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/default.html
|
124
|
-
document = open("#{File.dirname( __FILE__ )}/dummy.html")
|
124
|
+
document = open("#{File.dirname( __FILE__ )}/dummy.html").read
|
125
125
|
result = Tube::StatusParser.parse(document)
|
126
126
|
|
127
127
|
assert(result)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Sadler
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-09 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|