tube 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/service_board.rb +4 -2
- data/lib/tube/status_parser.rb +7 -4
- data/test/dummy.html +8 -3
- data/test/status_parser_test.rb +2 -2
- metadata +9 -20
data/examples/service_board.rb
CHANGED
@@ -7,7 +7,7 @@ class String
|
|
7
7
|
end
|
8
8
|
|
9
9
|
LINE_COLORS = {
|
10
|
-
:bakerloo => [:bright_white, :
|
10
|
+
:bakerloo => [:bright_white, :red_bg],
|
11
11
|
:central => [:white, :bright_red_bg],
|
12
12
|
:circle => [:blue, :bright_yellow_bg],
|
13
13
|
:district => [:bright_white, :green_bg],
|
@@ -17,7 +17,9 @@ LINE_COLORS = {
|
|
17
17
|
:northern => [:bright_white, :black_bg],
|
18
18
|
:piccadilly => [:bright_white, :blue_bg],
|
19
19
|
:victoria => [:bright_white, :bright_blue_bg],
|
20
|
-
:waterlooandcity => [:blue, :bright_cyan_bg]
|
20
|
+
:waterlooandcity => [:blue, :bright_cyan_bg],
|
21
|
+
:dlr => [:bright_white, :cyan_bg],
|
22
|
+
:overground => [:bright_white, :yellow_bg]
|
21
23
|
}
|
22
24
|
STATUS_COLOR = [:blue, :bright_white_bg]
|
23
25
|
PROBLEM_COLOR = STATUS_COLOR + [:negative]
|
data/lib/tube/status_parser.rb
CHANGED
@@ -9,11 +9,13 @@ module Tube # :nodoc:
|
|
9
9
|
|
10
10
|
def parse( html_doc )
|
11
11
|
html_doc.gsub!( / /, " " )
|
12
|
-
|
12
|
+
doc = Nokogiri::HTML( html_doc )
|
13
13
|
|
14
|
-
updated_element =
|
14
|
+
updated_element = doc.at_css( "div.hd-row > h2" )
|
15
15
|
updated = parse_updated( updated_element )
|
16
16
|
|
17
|
+
service_board = doc.at_css( "#service-board" )
|
18
|
+
|
17
19
|
line_elements = service_board.css( "ul#lines > li.ltn-line" )
|
18
20
|
lines = line_elements.map( &method( :parse_line ) )
|
19
21
|
|
@@ -31,8 +33,9 @@ module Tube # :nodoc:
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def parse_line( line_element )
|
34
|
-
|
35
|
-
|
36
|
+
name_element = line_element.at_css( "h3.ltn-name" )
|
37
|
+
name = name_element.content
|
38
|
+
html_class = name_element["class"].split.first
|
36
39
|
status = parse_status( line_element.at_css( "div.status" ) )
|
37
40
|
|
38
41
|
{:name => name, :html_class => html_class, :status => status}
|
data/test/dummy.html
CHANGED
@@ -31,15 +31,20 @@
|
|
31
31
|
<p>Get advance warning of weekend closures</p>
|
32
32
|
</div>
|
33
33
|
</div>
|
34
|
+
|
35
|
+
<div class="short-form">
|
36
|
+
<div class="clear"></div>
|
37
|
+
</div>
|
38
|
+
|
34
39
|
<div id="service-board">
|
35
40
|
<h2>Tube lines</h2>
|
36
41
|
<ul id="lines">
|
37
|
-
<li class="
|
42
|
+
<li class="ltn-line">
|
38
43
|
<h3 class="central ltn-name">Central</h3>
|
39
44
|
<div class="status">Good service</div>
|
40
45
|
</li>
|
41
46
|
|
42
|
-
<li class="
|
47
|
+
<li class="ltn-line">
|
43
48
|
<h3 class="district ltn-name">District</h3>
|
44
49
|
<div class="problem status">
|
45
50
|
<h4 class="ltn-title">Part closure</h4>
|
@@ -55,7 +60,7 @@
|
|
55
60
|
</div>
|
56
61
|
</li>
|
57
62
|
|
58
|
-
<li class="
|
63
|
+
<li class="ltn-line">
|
59
64
|
<h3 class="waterlooandcity ltn-name">Waterloo & City</h3>
|
60
65
|
<div class="problem status">
|
61
66
|
<h4 class="ltn-title">Planned closure</h4>
|
data/test/status_parser_test.rb
CHANGED
@@ -20,7 +20,7 @@ class TestStatusParser < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_parse_line
|
23
|
-
document = Nokogiri::HTML(%Q{<li class="
|
23
|
+
document = Nokogiri::HTML(%Q{<li class="ltn-line"><h3 class="central ltn-name">Central</h3><div class="status">Good service</div></li>})
|
24
24
|
element = document.at_css("li")
|
25
25
|
result = Tube::StatusParser.parse_line(element)
|
26
26
|
|
@@ -30,7 +30,7 @@ class TestStatusParser < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_parse_line_with_complex_name
|
33
|
-
document = Nokogiri::HTML(%Q{<li class="
|
33
|
+
document = Nokogiri::HTML(%Q{<li class="ltn-line"><h3 class="waterlooandcity ltn-name">Waterloo & City</h3><div class="status">Good service</div></li>})
|
34
34
|
element = document.at_css("li")
|
35
35
|
result = Tube::StatusParser.parse_line(element)
|
36
36
|
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 3
|
9
|
-
version: 0.2.3
|
4
|
+
version: 0.2.4
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Matthew Sadler
|
@@ -14,23 +9,19 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-
|
12
|
+
date: 2010-05-24 00:00:00 +01:00
|
18
13
|
default_executable:
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: nokogiri
|
22
|
-
|
23
|
-
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 4
|
30
|
-
- 1
|
31
23
|
version: 1.4.1
|
32
|
-
|
33
|
-
version_requirements: *id001
|
24
|
+
version:
|
34
25
|
description: A simple Ruby library to access the status of the London Underground network.
|
35
26
|
email: mat@sourcetagsandcodes.com
|
36
27
|
executables: []
|
@@ -62,20 +53,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
53
|
requirements:
|
63
54
|
- - ">="
|
64
55
|
- !ruby/object:Gem::Version
|
65
|
-
segments:
|
66
|
-
- 0
|
67
56
|
version: "0"
|
57
|
+
version:
|
68
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
59
|
requirements:
|
70
60
|
- - ">="
|
71
61
|
- !ruby/object:Gem::Version
|
72
|
-
segments:
|
73
|
-
- 0
|
74
62
|
version: "0"
|
63
|
+
version:
|
75
64
|
requirements: []
|
76
65
|
|
77
66
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.5
|
79
68
|
signing_key:
|
80
69
|
specification_version: 3
|
81
70
|
summary: Access the status of the London Underground network.
|