bart 0.0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/bart.rb +5 -0
- data/lib/bart/etd.rb +5 -1
- data/lib/bart/station.rb +15 -7
- metadata +50 -53
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 064df0969f562719437960c515e557b247f92781
|
4
|
+
data.tar.gz: 3d43ab3da80a0ec6edcfb1eecf567ee5bf2d6187
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4029542cec61b7a4be2b4e79f721fd7975844905963ff46ea116846a06eb8d7d1b3d411bbd03a21ec7e9dc634da8b44f04e6ae5b436a26a5e415f69664f99fd4
|
7
|
+
data.tar.gz: 4348728bf67614008a5117681fbf72679b56b61adeedabbc0dcf4eee7696721c1376f807b7fa622bc3ac91064f70f25ba4d7152e8d884242e0670c7ce82d2b95
|
data/lib/bart.rb
ADDED
data/lib/bart/etd.rb
CHANGED
@@ -11,9 +11,13 @@ module Bart
|
|
11
11
|
abbr = document.css('abbreviation').text
|
12
12
|
estimates = document.css('estimate')
|
13
13
|
|
14
|
-
@destination = Station.new(abbr)
|
14
|
+
@destination = Station.new(abbr: abbr)
|
15
15
|
@estimates = estimates.inject([]) { |memo, i| memo << Estimate.new(i.to_s) }
|
16
16
|
end
|
17
17
|
|
18
|
+
def to_s
|
19
|
+
"#{destination.name} #{estimates.map(&:minutes) * ', '}"
|
20
|
+
end
|
21
|
+
|
18
22
|
end
|
19
23
|
end
|
data/lib/bart/station.rb
CHANGED
@@ -14,7 +14,6 @@ module Bart
|
|
14
14
|
class Station
|
15
15
|
|
16
16
|
attr_reader :abbr
|
17
|
-
attr_accessor :departures
|
18
17
|
|
19
18
|
# DEBUG
|
20
19
|
attr_reader :document
|
@@ -22,8 +21,8 @@ module Bart
|
|
22
21
|
# OPTIMIZE If we have one station object, we don't need to initialize
|
23
22
|
# new ones over and over again. We'll leave it alone for now, for
|
24
23
|
# simplicity.
|
25
|
-
def initialize(
|
26
|
-
@abbr = abbr.downcase
|
24
|
+
def initialize(options = {})
|
25
|
+
@abbr = options[:abbr] ? options[:abbr].downcase : nil
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.from_xml(xml)
|
@@ -43,14 +42,23 @@ module Bart
|
|
43
42
|
ID_TO_NAME[abbr]
|
44
43
|
end
|
45
44
|
|
45
|
+
def departures
|
46
|
+
return @_departures if defined?(@_departures);
|
47
|
+
@_departures = load_departures
|
48
|
+
end
|
49
|
+
|
46
50
|
# fetch
|
47
|
-
def load_departures
|
51
|
+
def load_departures(query_params = {})
|
48
52
|
params = {
|
49
53
|
:cmd => 'etd',
|
50
54
|
:orig => @abbr,
|
51
55
|
:key => 'MW9S-E7SL-26DU-VV8V'
|
52
56
|
}
|
53
57
|
|
58
|
+
[:plat, :dir].each do |param|
|
59
|
+
params[param] = query_params[param] if query_params.include?(param)
|
60
|
+
end
|
61
|
+
|
54
62
|
query_string = '?' + params.map { |key, value| [key, value] * '=' } * '&'
|
55
63
|
ssan_etd = Net::HTTP::Get.new('/api/etd.aspx' + query_string )
|
56
64
|
|
@@ -58,13 +66,13 @@ module Bart
|
|
58
66
|
http.request(ssan_etd)
|
59
67
|
end
|
60
68
|
|
61
|
-
|
69
|
+
parse_departures(response.body)
|
62
70
|
end
|
63
71
|
|
64
|
-
def
|
72
|
+
def parse_departures(xml)
|
65
73
|
document = Nokogiri::XML.parse(xml)
|
66
74
|
@document = document
|
67
|
-
|
75
|
+
document.css('etd').inject([]) do |memo, i|
|
68
76
|
memo << Etd.new(i.to_s)
|
69
77
|
end
|
70
78
|
end
|
metadata
CHANGED
@@ -1,79 +1,76 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bart
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Josh Lubaway
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2010-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: nokogiri
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
31
20
|
type: :runtime
|
32
|
-
|
33
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fakeweb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
description: Access the Bay Area Rapid Transit API in Ruby.
|
34
42
|
email: josh.lubaway@gmail.com
|
35
43
|
executables: []
|
36
|
-
|
37
44
|
extensions: []
|
38
|
-
|
39
45
|
extra_rdoc_files: []
|
40
|
-
|
41
|
-
|
46
|
+
files:
|
47
|
+
- lib/bart.rb
|
42
48
|
- lib/bart/estimate.rb
|
43
49
|
- lib/bart/etd.rb
|
44
|
-
- lib/bart/station/list.rb
|
45
50
|
- lib/bart/station.rb
|
46
|
-
|
51
|
+
- lib/bart/station/list.rb
|
47
52
|
homepage: https://github.com/jish/bart
|
48
|
-
licenses:
|
49
|
-
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
50
56
|
post_install_message:
|
51
57
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
58
|
+
require_paths:
|
54
59
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
requirements:
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
58
62
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
|
-
requirements:
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
66
67
|
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
71
70
|
requirements: []
|
72
|
-
|
73
71
|
rubyforge_project:
|
74
|
-
rubygems_version:
|
72
|
+
rubygems_version: 2.2.2
|
75
73
|
signing_key:
|
76
|
-
specification_version:
|
74
|
+
specification_version: 4
|
77
75
|
summary: A ruby wrapper around the BART API.
|
78
76
|
test_files: []
|
79
|
-
|