translink 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +12 -0
- data/README.md +44 -8
- data/doc/schema.graffle +396 -82
- data/doc/schema.png +0 -0
- data/lib/translink/cli.rb +10 -16
- data/lib/translink/crawler.rb +5 -6
- data/lib/translink/db.rb +6 -14
- data/lib/translink/model/route.rb +29 -18
- data/lib/translink/model/stop.rb +17 -19
- data/lib/translink/model/stop_time.rb +26 -0
- data/lib/translink/model/trip.rb +48 -0
- data/lib/translink/page/route.rb +42 -18
- data/lib/translink/page/timetable.rb +15 -18
- data/lib/translink/page/trip.rb +90 -17
- data/lib/translink/page.rb +1 -1
- data/lib/translink/version.rb +1 -1
- data/lib/translink.rb +2 -3
- data/test/fixtures/sample/route.html +401 -1049
- data/test/fixtures/sample/timetable.html +170 -216
- data/test/fixtures/verbatim/route.html +1976 -7178
- data/test/fixtures/verbatim/timetable.html +1501 -6165
- data/test/fixtures/verbatim/trip.html +311 -508
- data/test/unit/cli_test.rb +4 -20
- data/test/unit/crawler_test.rb +16 -36
- data/test/unit/model/route_test.rb +14 -25
- data/test/unit/model/stop_test.rb +6 -31
- data/test/unit/model/stop_time_test.rb +11 -0
- data/test/unit/model/trip_test.rb +28 -0
- data/test/unit/page/route_test.rb +38 -28
- data/test/unit/page/timetable_test.rb +12 -10
- data/test/unit/page/trip_test.rb +38 -22
- data/test/unit/page_test.rb +1 -1
- data/translink.gemspec +2 -2
- metadata +24 -27
- data/lib/translink/code.rb +0 -9
- data/lib/translink/model/service.rb +0 -20
- data/lib/translink/model/stop/extractor.rb +0 -67
- data/test/unit/code_test.rb +0 -12
- data/test/unit/model/service_test.rb +0 -23
- data/test/unit/model/stop/extractor_test.rb +0 -112
data/lib/translink/code.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Translink
|
2
|
-
module Model
|
3
|
-
class Service
|
4
|
-
include DataMapper::Resource
|
5
|
-
|
6
|
-
property :id, Serial
|
7
|
-
property :time, DateTime
|
8
|
-
|
9
|
-
belongs_to :route
|
10
|
-
belongs_to :stop
|
11
|
-
|
12
|
-
def self.build_from_trip trip
|
13
|
-
new.tap do |service|
|
14
|
-
service.stop = Stop.find_or_add_from_stop trip.stop
|
15
|
-
service.time = trip.time
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module Translink
|
2
|
-
module Model
|
3
|
-
class Stop::Extractor
|
4
|
-
module Nil
|
5
|
-
def gsub *args
|
6
|
-
self
|
7
|
-
end
|
8
|
-
|
9
|
-
def strip
|
10
|
-
self
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
REGEXES = {
|
15
|
-
/[\s\(]opposite approaching/i => 'opposite_approaching',
|
16
|
-
/[\s\(]opposite far side of/i => 'opposite_far_side',
|
17
|
-
/[\s\(]opposite/i => 'opposite',
|
18
|
-
/[\s\(]approaching/i => 'approaching',
|
19
|
-
/[\s\(]far side of/i => 'far_side',
|
20
|
-
/[\s\(]at/i => 'at',
|
21
|
-
/[\s\(]near/i => 'near'
|
22
|
-
}
|
23
|
-
|
24
|
-
attr_accessor :stop
|
25
|
-
|
26
|
-
def initialize stop
|
27
|
-
@stop = stop
|
28
|
-
end
|
29
|
-
|
30
|
-
def extract!
|
31
|
-
stop.street1 = street1
|
32
|
-
stop.street2 = street2
|
33
|
-
stop.locality = locality
|
34
|
-
stop
|
35
|
-
end
|
36
|
-
|
37
|
-
def street1
|
38
|
-
segment = segments.first
|
39
|
-
segment =~ /,\s*(.+)/
|
40
|
-
($1 || segment).strip
|
41
|
-
end
|
42
|
-
|
43
|
-
def street2
|
44
|
-
segments.last.gsub(/[\(\)]/, '').strip
|
45
|
-
end
|
46
|
-
|
47
|
-
def locality
|
48
|
-
REGEXES[regex]
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
def regex
|
54
|
-
REGEXES.keys.find { |regex| summary_or_name =~ regex }
|
55
|
-
end
|
56
|
-
|
57
|
-
def segments
|
58
|
-
results = summary_or_name.split regex
|
59
|
-
results.size == 2 ? results : [summary_or_name, nil.extend(Nil)]
|
60
|
-
end
|
61
|
-
|
62
|
-
def summary_or_name
|
63
|
-
stop.summary ? stop.summary : stop.name
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/test/unit/code_test.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class CodeTest < MiniTest::Unit::TestCase
|
4
|
-
def test_brisbane
|
5
|
-
refute Code.brisbane?('10')
|
6
|
-
assert Code.brisbane?('100')
|
7
|
-
assert Code.brisbane?('499')
|
8
|
-
assert Code.brisbane?('GLIDER')
|
9
|
-
assert Code.brisbane?('LOOP')
|
10
|
-
refute Code.brisbane?('500')
|
11
|
-
end
|
12
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Model::ServiceTest < MiniTest::Unit::TestCase
|
4
|
-
class Trip
|
5
|
-
def stop
|
6
|
-
Model::Stop.first_or_create :name => 'Stop'
|
7
|
-
end
|
8
|
-
|
9
|
-
def time
|
10
|
-
DateTime.parse '2011-12-03 18:24:00'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_build_from_trip
|
15
|
-
DB.new 'sqlite::memory:' do
|
16
|
-
trip = Trip.new
|
17
|
-
service = Model::Service.build_from_trip trip
|
18
|
-
assert_equal trip.stop, service.stop
|
19
|
-
assert_equal trip.time, service.time
|
20
|
-
assert_instance_of Model::Service, service
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Model::Stop::ExtractorTest < MiniTest::Unit::TestCase
|
4
|
-
def stub_extractor attributes
|
5
|
-
Model::Stop::Extractor.new OpenStruct.new(attributes)
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_extract!
|
9
|
-
stop = OpenStruct.new :summary => 'Grand Ave East, Grand Av opposite approaching Ascot Av'
|
10
|
-
extractor = Model::Stop::Extractor.new stop
|
11
|
-
assert_same stop, extractor.extract!
|
12
|
-
assert_equal 'Grand Av', stop.street1
|
13
|
-
assert_equal 'Ascot Av', stop.street2
|
14
|
-
assert_equal 'opposite_approaching', stop.locality
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_street1_opposite_approaching
|
18
|
-
assert_equal 'Grand Av', stub_extractor(:summary => 'Grand Ave East, Grand Av opposite approaching Ascot Av').street1
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_street2_opposite_approaching
|
22
|
-
assert_equal 'Ascot Av', stub_extractor(:summary => 'Grand Ave East, Grand Av opposite approaching Ascot Av').street2
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_locality_opposite_approaching
|
26
|
-
assert_equal 'opposite_approaching', stub_extractor(:summary => 'Grand Ave East, Grand Av opposite approaching Ascot Av').locality
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_street1_opposite_far_side
|
30
|
-
assert_equal 'Ipswich Rd', stub_extractor(:summary => 'P.A. Hospital - 14, Ipswich Rd opposite far side of Tottenham St').street1
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_street2_opposite_far_side
|
34
|
-
assert_equal 'Tottenham St', stub_extractor(:summary => 'P.A. Hospital - 14, Ipswich Rd opposite far side of Tottenham St').street2
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_locality_opposite_far_side
|
38
|
-
assert_equal 'opposite_far_side', stub_extractor(:summary => 'P.A. Hospital - 14, Ipswich Rd opposite far side of Tottenham St').locality
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_street1_opposite
|
42
|
-
assert_equal 'Partridge St', stub_extractor(:summary => 'Partridge, Partridge St opposite Tang St').street1
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_street2_opposite
|
46
|
-
assert_equal 'Tang St', stub_extractor(:summary => 'Partridge, Partridge St opposite Tang St').street2
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_locality_opposite
|
50
|
-
assert_equal 'opposite', stub_extractor(:summary => 'Partridge, Partridge St opposite Tang St').locality
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_street1_appraoching
|
54
|
-
assert_equal 'Blunder Rd', stub_extractor(:summary => 'Stop 66, Blunder Rd (approaching Ipswich Rd)').street1
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_street2_appraoching
|
58
|
-
assert_equal 'Ipswich Rd', stub_extractor(:summary => 'Stop 66, Blunder Rd (approaching Ipswich Rd)').street2
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_locality_appraoching
|
62
|
-
assert_equal 'approaching', stub_extractor(:summary => 'Stop 66, Blunder Rd (approaching Ipswich Rd)').locality
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_street1_far_side
|
66
|
-
assert_equal 'Illaweena St', stub_extractor(:summary => 'Waterstone, Illaweena St far side of Waterbrooke Crt').street1
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_street2_far_side
|
70
|
-
assert_equal 'Waterbrooke Crt', stub_extractor(:summary => 'Waterstone, Illaweena St far side of Waterbrooke Crt').street2
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_locality_far_side
|
74
|
-
assert_equal 'far_side', stub_extractor(:summary => 'Waterstone, Illaweena St far side of Waterbrooke Crt').locality
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_street1_at
|
78
|
-
assert_equal 'South East Busway', stub_extractor(:summary => 'Woolloongabba Platform 1, South East Busway At Main St').street1
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_street2_at
|
82
|
-
assert_equal 'Main St', stub_extractor(:summary => 'Woolloongabba Platform 1, South East Busway At Main St').street2
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_locality_at
|
86
|
-
assert_equal 'at', stub_extractor(:summary => 'Woolloongabba Platform 1, South East Busway At Main St').locality
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_street1_near
|
90
|
-
assert_equal 'Old Northern Rd', stub_extractor(:summary => 'Allamanda, Old Northern Rd (Near Allamanda Cres)').street1
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_street2_near
|
94
|
-
assert_equal 'Allamanda Cres', stub_extractor(:summary => 'Allamanda, Old Northern Rd (Near Allamanda Cres)').street2
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_locality_near
|
98
|
-
assert_equal 'near', stub_extractor(:summary => 'Allamanda, Old Northern Rd (Near Allamanda Cres)').locality
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_street1_without_locality
|
102
|
-
assert_equal 'Oyster Cove - Hail And Ride', stub_extractor(:name => 'Oyster Cove - Hail And Ride').street1
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_street2_without_locality
|
106
|
-
assert_nil stub_extractor(:name => 'Oyster Cove - Hail And Ride').street2
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_locality_without_locality
|
110
|
-
assert_nil stub_extractor(:name => 'Oyster Cove - Hail And Ride').locality
|
111
|
-
end
|
112
|
-
end
|