slurpy 0.0.1 → 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 +4 -4
- data/README.md +4 -4
- data/lib/slurpy.rb +2 -2
- data/lib/slurpy/slurpy.rb +37 -12
- data/lib/slurpy/version.rb +1 -1
- data/slurpy.gemspec +1 -0
- data/spec/slurpy_spec.rb +13 -12
- metadata +16 -4
- data/lib/rubocop_report +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 246cc873f48ba260818b7c06b8b11aa479e97f43
|
4
|
+
data.tar.gz: f8f2707a84de288e90e87f9796fc151baf2a0c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c09b450c8f1aa1aa7101e5529bd70c2090fa50008a8611ec20062187f7ee3d0306af16dbc5b5a624eb36110469dc3040fc2cd7394ed6e4df1df3034ee2b7224
|
7
|
+
data.tar.gz: 404f94d25caa42ac760af83f85bd59c929a8ca085c051c79fdae67099ca0f8dc0565fa1f108d6283c4e46b4dfaa07a45800ccd999c83503ec056fb7d32de9e8f
|
data/README.md
CHANGED
@@ -16,11 +16,11 @@ Use by doing the following:
|
|
16
16
|
|
17
17
|
$ slurpy next "Day 1" "Convention"
|
18
18
|
|
19
|
-
to get the next stop time for any SLU shuttle going from "Day 1 North" to "Convention
|
19
|
+
to get the next stop time for any SLU shuttle going from "Day 1 North" to "Convention Place".
|
20
20
|
|
21
21
|
You can also set your defaults in ~/.slurpy like so
|
22
22
|
|
23
|
-
$ slurpy config
|
23
|
+
$ slurpy config --origin 'Day 1 North' --destination 'Convention Place'
|
24
24
|
|
25
25
|
and then do
|
26
26
|
|
@@ -28,8 +28,8 @@ and then do
|
|
28
28
|
$ slurpy next --return
|
29
29
|
$ slurpy next "Blackfoot"
|
30
30
|
|
31
|
-
* The first will search the times for the default route (Day 1 North -> Convention
|
32
|
-
* The second will search the times for the default route, inverted (Day 1 North -> Convention
|
31
|
+
* The first will search the times for the default route (Day 1 North -> Convention Place).
|
32
|
+
* The second will search the times for the default route, inverted (Day 1 North -> Convention Place)
|
33
33
|
* The third will search the times for the default origin (Prime) to Blackfoot
|
34
34
|
|
35
35
|
## Contributing
|
data/lib/slurpy.rb
CHANGED
data/lib/slurpy/slurpy.rb
CHANGED
@@ -9,10 +9,12 @@ require 'typhoeus'
|
|
9
9
|
require 'thor'
|
10
10
|
require 'api_cache'
|
11
11
|
require 'moneta'
|
12
|
+
require 'timezone'
|
12
13
|
|
13
14
|
class Slurpy < Thor
|
14
15
|
DEFAULTS_FILE = "#{Dir.home}/.slurpy"
|
15
16
|
CACHE_FOLDER = '/tmp/slurpy/cache'
|
17
|
+
TIMEZONE = 'America/Los_Angeles'
|
16
18
|
|
17
19
|
BASE_URL = 'http://www.slushuttle.com/Services/JSONPRelay.svc/'
|
18
20
|
|
@@ -29,7 +31,7 @@ class Slurpy < Thor
|
|
29
31
|
|
30
32
|
option :return, :type => :boolean
|
31
33
|
|
32
|
-
desc 'next origin
|
34
|
+
desc 'next origin destination', 'Returns the next routes from origin to destination'
|
33
35
|
def next(origin = defaults['origin'], destination = defaults['destination'])
|
34
36
|
|
35
37
|
origin, destination = destination, origin if options[:return]
|
@@ -48,7 +50,7 @@ class Slurpy < Thor
|
|
48
50
|
to_origin_shuttles[route_id] < to_destination_shuttles[route_id]
|
49
51
|
end
|
50
52
|
|
51
|
-
Slurpy.error "No shuttles from '#{origin_name}' to '#{destination_name}', sorry. " \
|
53
|
+
Slurpy.error "No shuttles from '#{origin_name}' to '#{destination_name}' right now, sorry. " \
|
52
54
|
"See http://www.slushuttle.com/ for more details." \
|
53
55
|
if origin_to_destination_shuttles.empty?
|
54
56
|
|
@@ -59,13 +61,34 @@ class Slurpy < Thor
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
64
|
+
method_option :origin, :type => :string, :required => true
|
65
|
+
method_option :destination, :type => :string, :required => true
|
66
|
+
|
67
|
+
desc 'config', 'Sets the defaults origin and destination'
|
68
|
+
def config
|
69
|
+
|
70
|
+
settings = {
|
71
|
+
'origin' => options[:origin],
|
72
|
+
'destination' => options[:destination]
|
73
|
+
}
|
74
|
+
|
75
|
+
File.open(DEFAULTS_FILE, "w") do |file|
|
76
|
+
file.write settings.to_yaml
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
private #####################################################################
|
63
81
|
|
64
82
|
def defaults
|
65
|
-
Slurpy.error 'Slurpy needs params unless .slurpy exists' unless
|
83
|
+
Slurpy.error 'Slurpy needs params unless .slurpy exists' unless
|
66
84
|
File.exists?(DEFAULTS_FILE)
|
67
85
|
|
68
86
|
@defaults ||= ::YAML::load_file(DEFAULTS_FILE)
|
87
|
+
|
88
|
+
Slurpy.error 'Invalid default origin' unless @defaults['origin']
|
89
|
+
Slurpy.error 'Invalid default destination' unless @defaults['destination']
|
90
|
+
|
91
|
+
@defaults
|
69
92
|
end
|
70
93
|
|
71
94
|
def self.error(message)
|
@@ -128,18 +151,18 @@ class Slurpy < Thor
|
|
128
151
|
def self.get_stop(query)
|
129
152
|
Slurpy.from_cache "stop::#{query}", lambda {
|
130
153
|
infos = request(:stops)
|
131
|
-
.select { |stop| stop['Description'].include? query }
|
154
|
+
.select { |stop| stop['Description'].downcase.include? query.downcase }
|
132
155
|
|
133
156
|
stops = infos.map{ |stop| stop['Description']}.to_set.to_a
|
134
157
|
|
135
158
|
error = "No stop matches '#{query}', sorry." if stops.empty?
|
136
159
|
|
137
|
-
error = "Your request for stop '#{query}' is not specific enough. " \
|
138
|
-
|
160
|
+
#error = "Your request for stop '#{query}' is not specific enough. " \
|
161
|
+
# "Pick one: #{stops.inspect}" if stops.size > 1
|
139
162
|
|
140
163
|
Slurpy.error error if error
|
141
164
|
|
142
|
-
return infos, stops
|
165
|
+
return infos, stops
|
143
166
|
}
|
144
167
|
end
|
145
168
|
|
@@ -150,14 +173,16 @@ class Slurpy < Thor
|
|
150
173
|
|
151
174
|
def self.extract_date(date)
|
152
175
|
epoch_time_in_seconds = date
|
153
|
-
.to_s
|
176
|
+
.to_s
|
154
177
|
.scan(%r(/Date\((\d+)\)/))
|
155
|
-
.flatten.first
|
178
|
+
.flatten.first.to_i / 1000
|
156
179
|
|
157
180
|
Slurpy.error 'Failed to retrieve date from #{date}' unless epoch_time_in_seconds
|
158
|
-
|
159
|
-
|
181
|
+
|
182
|
+
timezone = Timezone::Zone.new :zone => TIMEZONE
|
183
|
+
|
184
|
+
timezone.time(Time.at(epoch_time_in_seconds)).strftime('%R')
|
160
185
|
end
|
161
186
|
end
|
162
187
|
|
163
|
-
Slurpy.start(ARGV)
|
188
|
+
Slurpy.start(ARGV)
|
data/lib/slurpy/version.rb
CHANGED
data/slurpy.gemspec
CHANGED
data/spec/slurpy_spec.rb
CHANGED
@@ -83,36 +83,37 @@ describe "slurpy" do
|
|
83
83
|
|
84
84
|
Slurpy.should_receive(:get_times).at_least(:once).times.and_return([
|
85
85
|
{"RouteID" => "1", "RouteStopID" => "1", "StopTimes" =>
|
86
|
-
[{"DepartureTime" => "\/Date\(0\)/"}, {"DepartureTime" => "\/Date\(
|
86
|
+
[{"DepartureTime" => "\/Date\(0\)/"}, {"DepartureTime" => "\/Date\(10000000\)/"}]},
|
87
87
|
{"RouteID" => "1", "RouteStopID" => "2", "StopTimes" =>
|
88
|
-
[{"DepartureTime" => "\/Date\(
|
88
|
+
[{"DepartureTime" => "\/Date\(10000000\)/"}, {"DepartureTime" => "\/Date\(30000000\)/"}]},
|
89
89
|
{"RouteID" => "2", "RouteStopID" => "1", "StopTimes" =>
|
90
|
-
[{"DepartureTime" => "\/Date\(
|
90
|
+
[{"DepartureTime" => "\/Date\(1000000\)/"}, {"DepartureTime" => "\/Date\(11000000\)/"}]},
|
91
91
|
{"RouteID" => "2", "RouteStopID" => "2", "StopTimes" =>
|
92
|
-
[{"DepartureTime" => "\/Date\(
|
92
|
+
[{"DepartureTime" => "\/Date\(11000000\)/"}, {"DepartureTime" => "\/Date\(30000000\)/"}]}
|
93
93
|
])
|
94
94
|
|
95
95
|
Slurpy.start(["next", "Day 1", "Convention"])
|
96
96
|
|
97
97
|
expect(capture(:stdout) { Slurpy.start(["next", "Day 1", "Convention"]) })
|
98
98
|
.to eq("Searching routes from 'Day 1 North' to 'Convention Center'...\n" \
|
99
|
-
"Route R10 - Departure:
|
100
|
-
"Route R11 - Departure:
|
99
|
+
"Route R10 - Departure: 16:00 Arrival: 18:46\n" \
|
100
|
+
"Route R11 - Departure: 16:16 Arrival: 19:03\n")
|
101
101
|
end
|
102
102
|
|
103
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'
|
104
|
+
Slurpy.should_receive(:error).once.with("No shuttles from 'Day 1 North' to 'Convention Center' " \
|
105
|
+
"right now, sorry. " \
|
105
106
|
"See http://www.slushuttle.com/ for more details.")
|
106
107
|
|
107
108
|
Slurpy.should_receive(:get_times).at_least(:once).times.and_return([
|
108
109
|
{"RouteID" => "1", "RouteStopID" => "1", "StopTimes" =>
|
109
|
-
[{"DepartureTime" => "\/Date\(0\)/"}, {"DepartureTime" => "\/Date\(
|
110
|
+
[{"DepartureTime" => "\/Date\(0\)/"}, {"DepartureTime" => "\/Date\(10000000\)/"}]},
|
110
111
|
{"RouteID" => "1", "RouteStopID" => "3", "StopTimes" =>
|
111
|
-
[{"DepartureTime" => "\/Date\(
|
112
|
+
[{"DepartureTime" => "\/Date\(10000000\)/"}, {"DepartureTime" => "\/Date\(30000000\)/"}]},
|
112
113
|
{"RouteID" => "2", "RouteStopID" => "1", "StopTimes" =>
|
113
|
-
[{"DepartureTime" => "\/Date\(
|
114
|
+
[{"DepartureTime" => "\/Date\(1000000\)/"}, {"DepartureTime" => "\/Date\(11000000\)/"}]},
|
114
115
|
{"RouteID" => "2", "RouteStopID" => "4", "StopTimes" =>
|
115
|
-
[{"DepartureTime" => "\/Date\(
|
116
|
+
[{"DepartureTime" => "\/Date\(11000000\)/"}, {"DepartureTime" => "\/Date\(30000000\)/"}]}
|
116
117
|
])
|
117
118
|
|
118
119
|
Slurpy.start(["next", "Day 1", "Convention"])
|
@@ -121,7 +122,7 @@ describe "slurpy" do
|
|
121
122
|
|
122
123
|
describe "extract_date" do
|
123
124
|
it "converts an epoch date to time" do
|
124
|
-
Slurpy.extract_date("\/Date\(
|
125
|
+
Slurpy.extract_date("\/Date\(1388318968000\)/").should eql "04:09"
|
125
126
|
end
|
126
127
|
end
|
127
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slurpy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Della Corte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timezone
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Retrieves the SLUShuttle times from the command line.
|
112
126
|
email:
|
113
127
|
- andreadellacorte85@gmail.com
|
@@ -124,7 +138,6 @@ files:
|
|
124
138
|
- README.md
|
125
139
|
- Rakefile
|
126
140
|
- bin/slurpy
|
127
|
-
- lib/rubocop_report
|
128
141
|
- lib/slurpy.rb
|
129
142
|
- lib/slurpy/slurpy.rb
|
130
143
|
- lib/slurpy/version.rb
|
@@ -159,4 +172,3 @@ summary: Command line interface for SLUShuttle.
|
|
159
172
|
test_files:
|
160
173
|
- spec/slurpy_spec.rb
|
161
174
|
- spec/spec_helper.rb
|
162
|
-
has_rdoc:
|
data/lib/rubocop_report
DELETED
@@ -1,19 +0,0 @@
|
|
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
|