tfl_journey_planner 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/tfl_journey_planner.rb +35 -9
- data/tfl_journey_planner.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/lib/tfl_journey_planner.rb
CHANGED
@@ -23,17 +23,43 @@ class TflJourneyPlanner
|
|
23
23
|
|
24
24
|
def get_journeys(from, to)
|
25
25
|
output = Nokogiri::HTML.parse(submit_form(from, to)).css('.un_space_top_bottom')
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
|
27
|
+
routes = output.map do |route|
|
28
|
+
process_route(route)
|
29
|
+
end.reject(&:empty?)
|
30
|
+
|
31
|
+
to_json(routes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_json(routes)
|
35
|
+
"[" + routes.map{ |r| "{" + r.join(", ") + "}" }.join(", ") + "]"
|
35
36
|
end
|
36
37
|
|
38
|
+
def process_route(route)
|
39
|
+
route.css('div').map do |attribute|
|
40
|
+
has_image?(attribute) ? process_interchanges(attribute) : process_attribute(attribute)
|
41
|
+
end.compact
|
42
|
+
end
|
43
|
+
|
44
|
+
def process_interchanges(attribute)
|
45
|
+
attribute.text.strip + images_urls(attribute).inspect
|
46
|
+
end
|
47
|
+
|
48
|
+
def images_urls(attribute)
|
49
|
+
attribute.css('img').map{ |i| CGI.unescape(i.attr('src')).split(/\=|\&/)[1] }
|
50
|
+
end
|
51
|
+
|
52
|
+
def process_attribute(attribute)
|
53
|
+
"'" + attribute.text.strip.sub(": ", "': '") + "'" if has_data?(attribute)
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_data?(attribute)
|
57
|
+
!attribute.text.empty? && attribute.text.split(":").length > 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def has_image?(attribute)
|
61
|
+
!attribute.css('img').empty?
|
62
|
+
end
|
37
63
|
end
|
38
64
|
|
39
65
|
end
|
data/tfl_journey_planner.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tfl_journey_planner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jordi Noguera
|