slurpy 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/slurpy +4 -0
- data/lib/rubocop_report +19 -0
- data/lib/slurpy/slurpy.rb +163 -0
- data/lib/slurpy/version.rb +3 -0
- data/lib/slurpy.rb +4 -0
- data/slurpy.gemspec +28 -0
- data/spec/slurpy_spec.rb +127 -0
- data/spec/spec_helper.rb +27 -0
- data/test +145 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84eed2ae7245d70deeb2ad3a5234e745cf5270ac
|
4
|
+
data.tar.gz: 3daf5b8c89349632146e7e690abd15ae18b98e3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f5f42c2aca8285ac086f3ef4884932b3262830c5aa30181517e2213a8ab228076d1bb80f6f7b5d8ae9a628d8136471e8c204fa0a459d42dfeb1593fc6101920
|
7
|
+
data.tar.gz: 94970fa6b47cff5180f9fb486525088908533a5afb3f42d0162921c248ea7a3bed2fe32e0115ca1d3e11bc4d9e15cd4b64f90885315b180fc58ffce4a094422a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Andrea
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrea Della Corte
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Slurpy
|
2
|
+
|
3
|
+
## S(outh)L(ake)U(nion)R(oute)P(lanner)(written in Rub)Y
|
4
|
+
|
5
|
+
This gem is a command line utility for http://www.slushuttle.com
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem using:
|
10
|
+
|
11
|
+
$ gem install slurpy
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Use by doing the following:
|
16
|
+
|
17
|
+
$ slurpy next "Day 1" "Convention"
|
18
|
+
|
19
|
+
to get the next stop time for any SLU shuttle going from "Day 1 North" to "Convention Seattle".
|
20
|
+
|
21
|
+
You can also set your defaults in ~/.slurpy like so
|
22
|
+
|
23
|
+
$ slurpy config {origin=> "Day 1 North", destination => "Convention Center"}
|
24
|
+
|
25
|
+
and then do
|
26
|
+
|
27
|
+
$ slurpy next
|
28
|
+
$ slurpy next --return
|
29
|
+
$ slurpy next "Blackfoot"
|
30
|
+
|
31
|
+
* The first will search the times for the default route (Day 1 North -> Convention Center).
|
32
|
+
* The second will search the times for the default route, inverted (Day 1 North -> Convention Center)
|
33
|
+
* The third will search the times for the default origin (Prime) to Blackfoot
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/slurpy
ADDED
data/lib/rubocop_report
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Inspecting 3 files
|
2
|
+
.EC
|
3
|
+
|
4
|
+
Offences:
|
5
|
+
|
6
|
+
slurpy/slurpy.rb:29:11: E: unexpected token tAMPER
|
7
|
+
&& to_origin_shuttles[route_id] < to_destination_shuttles[route_id]
|
8
|
+
^
|
9
|
+
slurpy/slurpy.rb:49:11: E: unexpected token tAMPER
|
10
|
+
&& time['RouteStopID'] == stop_id
|
11
|
+
^
|
12
|
+
slurpy/slurpy.rb:128:5: E: unexpected token tCONSTANT
|
13
|
+
Time.at(epoch_time_in_seconds).strftime("%R")
|
14
|
+
^^^^
|
15
|
+
slurpy/version.rb:1:1: C: Missing top-level module documentation comment.
|
16
|
+
module SlurpyMetadata
|
17
|
+
^^^^^^
|
18
|
+
|
19
|
+
3 files inspected, 4 offences detected
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# Ruby things
|
2
|
+
require 'pp'
|
3
|
+
require 'json'
|
4
|
+
require 'date'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
# Ruby gems
|
8
|
+
require 'typhoeus'
|
9
|
+
require 'thor'
|
10
|
+
require 'api_cache'
|
11
|
+
require 'moneta'
|
12
|
+
|
13
|
+
class Slurpy < Thor
|
14
|
+
DEFAULTS_FILE = "#{Dir.home}/.slurpy"
|
15
|
+
CACHE_FOLDER = '/tmp/slurpy/cache'
|
16
|
+
|
17
|
+
BASE_URL = 'http://www.slushuttle.com/Services/JSONPRelay.svc/'
|
18
|
+
|
19
|
+
RESOURCES = {
|
20
|
+
times: 'GetScheduleFutureStopTimes?TimesPerStopString=2',
|
21
|
+
stops: 'GetStops',
|
22
|
+
routes: 'GetRoutes'
|
23
|
+
}
|
24
|
+
|
25
|
+
def initialize *args
|
26
|
+
super
|
27
|
+
APICache.store = Moneta.new(:File, dir: CACHE_FOLDER)
|
28
|
+
end
|
29
|
+
|
30
|
+
option :return, :type => :boolean
|
31
|
+
|
32
|
+
desc 'next origin, destination', 'Returns the next routes from A to B'
|
33
|
+
def next(origin = defaults['origin'], destination = defaults['destination'])
|
34
|
+
|
35
|
+
origin, destination = destination, origin if options[:return]
|
36
|
+
|
37
|
+
to_origin_shuttles, origin_name = Slurpy.shuttles_for_stop origin
|
38
|
+
to_destination_shuttles, destination_name = Slurpy.shuttles_for_stop destination
|
39
|
+
|
40
|
+
puts "Searching routes from '#{origin_name}' to '#{destination_name}'..."
|
41
|
+
|
42
|
+
Slurpy.error 'Do you really want to go in circles?' if origin_name == destination_name
|
43
|
+
|
44
|
+
origin_to_destination_shuttles =
|
45
|
+
to_origin_shuttles
|
46
|
+
.select do |route_id, time|
|
47
|
+
to_destination_shuttles[route_id] &&
|
48
|
+
to_origin_shuttles[route_id] < to_destination_shuttles[route_id]
|
49
|
+
end
|
50
|
+
|
51
|
+
Slurpy.error "No shuttles from '#{origin_name}' to '#{destination_name}', sorry. " \
|
52
|
+
"See http://www.slushuttle.com/ for more details." \
|
53
|
+
if origin_to_destination_shuttles.empty?
|
54
|
+
|
55
|
+
origin_to_destination_shuttles.each do |route_id, time|
|
56
|
+
puts "#{Slurpy.get_route_by_id(route_id)['Description']} " \
|
57
|
+
"- Departure: #{to_origin_shuttles[route_id]} " \
|
58
|
+
"Arrival: #{to_destination_shuttles[route_id]}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private #####################################################################
|
63
|
+
|
64
|
+
def defaults
|
65
|
+
Slurpy.error 'Slurpy needs params unless .slurpy exists' unless
|
66
|
+
File.exists?(DEFAULTS_FILE)
|
67
|
+
|
68
|
+
@defaults ||= ::YAML::load_file(DEFAULTS_FILE)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.error(message)
|
72
|
+
puts "ERROR: #{message}"
|
73
|
+
exit 1
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.shuttles_for_stop(stop)
|
77
|
+
stops_info, stop_name = get_stop(stop)
|
78
|
+
|
79
|
+
stop_ids = stops_info.map { |stop_info| stop_info['RouteStopID'] }
|
80
|
+
|
81
|
+
shuttles = get_times
|
82
|
+
.select do |time|
|
83
|
+
stop_ids.include? time['RouteStopID']
|
84
|
+
end
|
85
|
+
.inject({}) do |route_to_stop_times, times|
|
86
|
+
route_to_stop_times.update(
|
87
|
+
times['RouteID'] => extract_date(times['StopTimes']
|
88
|
+
.first['DepartureTime'])
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
return shuttles, stop_name
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.from_cache(resource, lambda)
|
96
|
+
APICache.get(resource, period: 1, cache: 10) do
|
97
|
+
lambda.call
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.invalidate_cache
|
102
|
+
Moneta.new(:File, dir: CACHE_FOLDER).clear
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.request(resource)
|
106
|
+
Slurpy.from_cache "res::#{resource}", lambda {
|
107
|
+
JSON.parse(
|
108
|
+
Typhoeus.get("#{BASE_URL}#{RESOURCES[resource]}")
|
109
|
+
.response_body)
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.get_times
|
114
|
+
request(:times)
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.get_route(route_num)
|
118
|
+
Slurpy.from_cache "route::#{route_num}", lambda {
|
119
|
+
infos = request(:routes)
|
120
|
+
.select {|route| route['Description'].include? "(R#{route_num})" }
|
121
|
+
|
122
|
+
Slurpy.error "No route 'R#{route_num}', sorry." unless infos.size == 1
|
123
|
+
|
124
|
+
infos
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.get_stop(query)
|
129
|
+
Slurpy.from_cache "stop::#{query}", lambda {
|
130
|
+
infos = request(:stops)
|
131
|
+
.select { |stop| stop['Description'].include? query }
|
132
|
+
|
133
|
+
stops = infos.map{ |stop| stop['Description']}.to_set.to_a
|
134
|
+
|
135
|
+
error = "No stop matches '#{query}', sorry." if stops.empty?
|
136
|
+
|
137
|
+
error = "Your request for stop '#{query}' is not specific enough. " \
|
138
|
+
"Pick one: #{stops.inspect}" if stops.size > 1
|
139
|
+
|
140
|
+
Slurpy.error error if error
|
141
|
+
|
142
|
+
return infos, stops.first
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.get_route_by_id(route_id)
|
147
|
+
request(:routes)
|
148
|
+
.select { |route| route['RouteID'] == route_id.to_i }.first
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.extract_date(date)
|
152
|
+
epoch_time_in_seconds = date
|
153
|
+
.to_s
|
154
|
+
.scan(%r(/Date\((\d+)\)/))
|
155
|
+
.flatten.first
|
156
|
+
|
157
|
+
Slurpy.error 'Failed to retrieve date from #{date}' unless epoch_time_in_seconds
|
158
|
+
|
159
|
+
Time.at(epoch_time_in_seconds.to_i).strftime('%R')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
Slurpy.start(ARGV)
|
data/lib/slurpy.rb
ADDED
data/slurpy.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'slurpy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slurpy"
|
8
|
+
spec.version = SlurpyMetadata::VERSION
|
9
|
+
spec.authors = ["Andrea Della Corte"]
|
10
|
+
spec.email = ["andreadellacorte85@gmail.com"]
|
11
|
+
spec.description = %q{Retrieves the SLUShuttle times from the command line.}
|
12
|
+
spec.summary = %q{Command line interface for SLUShuttle.}
|
13
|
+
spec.homepage = "https://github.com/ValiumKnight/slurpy"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_runtime_dependency "typhoeus"
|
25
|
+
spec.add_runtime_dependency "thor"
|
26
|
+
spec.add_runtime_dependency "api_cache"
|
27
|
+
spec.add_runtime_dependency "moneta"
|
28
|
+
end
|
data/spec/slurpy_spec.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "slurpy" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
#IO.any_instance.stub(:puts)
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
Slurpy.invalidate_cache
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'caching' do
|
14
|
+
it "retrieves data from the cache instead of querying the service" do
|
15
|
+
response = OpenStruct.new
|
16
|
+
response.response_body = '{}'
|
17
|
+
|
18
|
+
Typhoeus.should_receive(:get).once.and_return(response)
|
19
|
+
|
20
|
+
Slurpy.get_times
|
21
|
+
sleep 1
|
22
|
+
Slurpy.get_times
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "get_stops" do
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
Slurpy.should_receive(:request).with(:stops).and_return(
|
30
|
+
[{'Description' => 'Day 1 North'},
|
31
|
+
{'Description' => 'Day 1 South'},
|
32
|
+
{'Description' => 'Convention'}])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the stops containing the query string" do
|
36
|
+
Slurpy.get_stop('Day 1 North').should eql [[{'Description' => 'Day 1 North'}], 'Day 1 North']
|
37
|
+
end
|
38
|
+
|
39
|
+
it "errors if no stop matches" do
|
40
|
+
Slurpy.should_receive(:error).once.with("No stop matches 'Unexisting', sorry.")
|
41
|
+
|
42
|
+
Slurpy.get_stop('Unexisting')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "errors if too many stops match" do
|
46
|
+
Slurpy.should_receive(:error).once.with("Your request for stop 'Day 1' is not specific enough. " \
|
47
|
+
"Pick one: [\"Day 1 North\", \"Day 1 South\"]")
|
48
|
+
|
49
|
+
Slurpy.get_stop('Day 1')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "get_route" do
|
54
|
+
before :each do
|
55
|
+
Slurpy.should_receive(:request).with(:routes).and_return(
|
56
|
+
[{'Description' => '(R1) Route'},
|
57
|
+
{'Description' => '(R2) Route'},
|
58
|
+
{'Description' => '(R11) Route'}])
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns the routes containing the query string" do
|
62
|
+
Slurpy.get_route('1').should eql [{'Description' => '(R1) Route'}]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "errors if no route matches" do
|
66
|
+
Slurpy.should_receive(:error).once.with("No route 'R22', sorry.")
|
67
|
+
|
68
|
+
Slurpy.get_route('22')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "next" do
|
73
|
+
|
74
|
+
before :each do
|
75
|
+
Slurpy.should_receive(:get_stop).at_least(:once).with('Day 1').and_return([[{'RouteStopID' => '1'}], 'Day 1 North'])
|
76
|
+
Slurpy.should_receive(:get_stop).at_least(:once).with('Convention').and_return([[{'RouteStopID' => '2'}], 'Convention Center'])
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns the next shuttles between a and b" do
|
80
|
+
|
81
|
+
Slurpy.should_receive(:get_route_by_id).at_least(:once).with('1').and_return({'Description' => 'Route R10'})
|
82
|
+
Slurpy.should_receive(:get_route_by_id).at_least(:once).with('2').and_return({'Description' => 'Route R11'})
|
83
|
+
|
84
|
+
Slurpy.should_receive(:get_times).at_least(:once).times.and_return([
|
85
|
+
{"RouteID" => "1", "RouteStopID" => "1", "StopTimes" =>
|
86
|
+
[{"DepartureTime" => "\/Date\(0\)/"}, {"DepartureTime" => "\/Date\(10000\)/"}]},
|
87
|
+
{"RouteID" => "1", "RouteStopID" => "2", "StopTimes" =>
|
88
|
+
[{"DepartureTime" => "\/Date\(10000\)/"}, {"DepartureTime" => "\/Date\(30000\)/"}]},
|
89
|
+
{"RouteID" => "2", "RouteStopID" => "1", "StopTimes" =>
|
90
|
+
[{"DepartureTime" => "\/Date\(1000\)/"}, {"DepartureTime" => "\/Date\(11000\)/"}]},
|
91
|
+
{"RouteID" => "2", "RouteStopID" => "2", "StopTimes" =>
|
92
|
+
[{"DepartureTime" => "\/Date\(11000\)/"}, {"DepartureTime" => "\/Date\(30000\)/"}]}
|
93
|
+
])
|
94
|
+
|
95
|
+
Slurpy.start(["next", "Day 1", "Convention"])
|
96
|
+
|
97
|
+
expect(capture(:stdout) { Slurpy.start(["next", "Day 1", "Convention"]) })
|
98
|
+
.to eq("Searching routes from 'Day 1 North' to 'Convention Center'...\n" \
|
99
|
+
"Route R10 - Departure: 19:00 Arrival: 21:46\n" \
|
100
|
+
"Route R11 - Departure: 19:16 Arrival: 22:03\n")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "errors if no route between a and b exists" do
|
104
|
+
Slurpy.should_receive(:error).once.with("No shuttles from 'Day 1 North' to 'Convention Center', sorry. " \
|
105
|
+
"See http://www.slushuttle.com/ for more details.")
|
106
|
+
|
107
|
+
Slurpy.should_receive(:get_times).at_least(:once).times.and_return([
|
108
|
+
{"RouteID" => "1", "RouteStopID" => "1", "StopTimes" =>
|
109
|
+
[{"DepartureTime" => "\/Date\(0\)/"}, {"DepartureTime" => "\/Date\(10000\)/"}]},
|
110
|
+
{"RouteID" => "1", "RouteStopID" => "3", "StopTimes" =>
|
111
|
+
[{"DepartureTime" => "\/Date\(10000\)/"}, {"DepartureTime" => "\/Date\(30000\)/"}]},
|
112
|
+
{"RouteID" => "2", "RouteStopID" => "1", "StopTimes" =>
|
113
|
+
[{"DepartureTime" => "\/Date\(1000\)/"}, {"DepartureTime" => "\/Date\(11000\)/"}]},
|
114
|
+
{"RouteID" => "2", "RouteStopID" => "4", "StopTimes" =>
|
115
|
+
[{"DepartureTime" => "\/Date\(11000\)/"}, {"DepartureTime" => "\/Date\(30000\)/"}]}
|
116
|
+
])
|
117
|
+
|
118
|
+
Slurpy.start(["next", "Day 1", "Convention"])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "extract_date" do
|
123
|
+
it "converts an epoch date to time" do
|
124
|
+
Slurpy.extract_date("\/Date\(10000\)/").should eql "21:46"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'slurpy'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
7
|
+
# loaded once.
|
8
|
+
#
|
9
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
end
|
15
|
+
|
16
|
+
def capture(stream)
|
17
|
+
begin
|
18
|
+
stream = stream.to_s
|
19
|
+
eval "$#{stream} = StringIO.new"
|
20
|
+
yield
|
21
|
+
result = eval("$#{stream}").string
|
22
|
+
ensure
|
23
|
+
eval("$#{stream} = #{stream.upcase}")
|
24
|
+
end
|
25
|
+
|
26
|
+
result
|
27
|
+
end
|
data/test
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"RouteID": 31,
|
4
|
+
"RouteStopID": 71,
|
5
|
+
"StopTimes": [
|
6
|
+
{
|
7
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
8
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
9
|
+
"EstimateTime": "/Date(1385329615520)/",
|
10
|
+
"SecondsToStop": 605,
|
11
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
12
|
+
}
|
13
|
+
]
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"RouteID": 31,
|
17
|
+
"RouteStopID": 72,
|
18
|
+
"StopTimes": [
|
19
|
+
{
|
20
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
21
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
22
|
+
"EstimateTime": "/Date(1385329305520)/",
|
23
|
+
"SecondsToStop": 295,
|
24
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
25
|
+
}
|
26
|
+
]
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"RouteID": 31,
|
30
|
+
"RouteStopID": 73,
|
31
|
+
"StopTimes": [
|
32
|
+
{
|
33
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
34
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
35
|
+
"EstimateTime": "/Date(1385329065520)/",
|
36
|
+
"SecondsToStop": 55,
|
37
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
38
|
+
}
|
39
|
+
]
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"RouteID": 31,
|
43
|
+
"RouteStopID": 148,
|
44
|
+
"StopTimes": [
|
45
|
+
{
|
46
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
47
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
48
|
+
"EstimateTime": "/Date(1385329855520)/",
|
49
|
+
"SecondsToStop": 845,
|
50
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
51
|
+
}
|
52
|
+
]
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"RouteID": 31,
|
56
|
+
"RouteStopID": 178,
|
57
|
+
"StopTimes": [
|
58
|
+
{
|
59
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
60
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
61
|
+
"EstimateTime": "/Date(1385329545520)/",
|
62
|
+
"SecondsToStop": 535,
|
63
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
64
|
+
}
|
65
|
+
]
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"RouteID": 38,
|
69
|
+
"RouteStopID": 113,
|
70
|
+
"StopTimes": [
|
71
|
+
{
|
72
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
73
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
74
|
+
"EstimateTime": "/Date(1385329649520)/",
|
75
|
+
"SecondsToStop": 640,
|
76
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
77
|
+
}
|
78
|
+
]
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"RouteID": 38,
|
82
|
+
"RouteStopID": 114,
|
83
|
+
"StopTimes": [
|
84
|
+
{
|
85
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
86
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
87
|
+
"EstimateTime": "/Date(1385329829520)/",
|
88
|
+
"SecondsToStop": 820,
|
89
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
90
|
+
}
|
91
|
+
]
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"RouteID": 38,
|
95
|
+
"RouteStopID": 115,
|
96
|
+
"StopTimes": [
|
97
|
+
{
|
98
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
99
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
100
|
+
"EstimateTime": "/Date(1385329039520)/",
|
101
|
+
"SecondsToStop": 30,
|
102
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
103
|
+
}
|
104
|
+
]
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"RouteID": 38,
|
108
|
+
"RouteStopID": 116,
|
109
|
+
"StopTimes": [
|
110
|
+
{
|
111
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
112
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
113
|
+
"EstimateTime": "/Date(1385329399520)/",
|
114
|
+
"SecondsToStop": 390,
|
115
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
116
|
+
}
|
117
|
+
]
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"RouteID": 38,
|
121
|
+
"RouteStopID": 176,
|
122
|
+
"StopTimes": [
|
123
|
+
{
|
124
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
125
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
126
|
+
"EstimateTime": "/Date(1385329579520)/",
|
127
|
+
"SecondsToStop": 570,
|
128
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
129
|
+
}
|
130
|
+
]
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"RouteID": 38,
|
134
|
+
"RouteStopID": 192,
|
135
|
+
"StopTimes": [
|
136
|
+
{
|
137
|
+
"ArrivalTime": "/Date(-62135575200000-0600)/",
|
138
|
+
"DepartureTime": "/Date(-62135575200000-0600)/",
|
139
|
+
"EstimateTime": "/Date(1385330069520)/",
|
140
|
+
"SecondsToStop": 1060,
|
141
|
+
"StopTime": "/Date(-62135575200000-0600)/"
|
142
|
+
}
|
143
|
+
]
|
144
|
+
}
|
145
|
+
]
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slurpy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrea Della Corte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: typhoeus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: api_cache
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: moneta
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Retrieves the SLUShuttle times from the command line.
|
112
|
+
email:
|
113
|
+
- andreadellacorte85@gmail.com
|
114
|
+
executables:
|
115
|
+
- slurpy
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/slurpy
|
127
|
+
- lib/rubocop_report
|
128
|
+
- lib/slurpy.rb
|
129
|
+
- lib/slurpy/slurpy.rb
|
130
|
+
- lib/slurpy/version.rb
|
131
|
+
- slurpy.gemspec
|
132
|
+
- spec/slurpy_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- test
|
135
|
+
homepage: https://github.com/ValiumKnight/slurpy
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.1.11
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Command line interface for SLUShuttle.
|
159
|
+
test_files:
|
160
|
+
- spec/slurpy_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
has_rdoc:
|