route_c 0.1.3 → 0.2.0
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 +8 -8
- data/README.md +6 -0
- data/config/config.yaml +12 -0
- data/lib/route_c/cli.rb +6 -2
- data/lib/route_c/config.rb +30 -0
- data/lib/route_c/lights.rb +5 -13
- data/lib/route_c/query.rb +4 -8
- data/lib/route_c/version.rb +1 -1
- data/lib/route_c.rb +1 -0
- metadata +2 -2
- data/config/pins.yaml +0 -11
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDkwYTg0Y2YwMjNkNTM3NjI0NTQ1NDU1YWM1MDQyZTU4ODIzMjc4Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWRlMzZjNGE4YjFiZWM0ZDg5ZjZjNjNkZjU5ZTM4NGZlZTQ2MTI4Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OThhZDFhYmM4Njg3MmIwNjE4YTIwN2FmMDdmYzk4ZTc5YWNjNzJiZWI2ZTM4
|
10
|
+
MjRjYzMwNTc3MGRmNzc4YjM5YzFkYmNlYTM3YWM1ODhkMmIzZWNiNDYwNjM5
|
11
|
+
NGQ4NjA5NTQwZTZkNGUyNWYzNTFmZGI4ODdjMmQwODRhZDNhNzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTQ1MTFmYzIzOWQ0ZTU3YzM4ZjIyYTkzMjY5ZmY5NzYwZTlkOTI3YzVmMmRi
|
14
|
+
ZDE2MzNiM2U5ZTJiODRiODNkZmVhYWE5ZjY4ZmU4ZTIxMzUxODRmZjY1OTkx
|
15
|
+
NjAyNTVmYmI1NDU3OTYxM2JhMjRmYTAzNGNlZThlY2RjNWM1M2Y=
|
data/README.md
CHANGED
@@ -4,3 +4,9 @@
|
|
4
4
|
[](https://codeclimate.com/github/TheODI-UD2D/route_c)
|
5
5
|
[](https://rubygems.org/gems/route_c)
|
6
6
|
[](http://TheODI-UD2D.mit-license.org)
|
7
|
+
|
8
|
+
# Crudely-drawn circuit
|
9
|
+
|
10
|
+

|
11
|
+
|
12
|
+
You might also need the [Treasure Map](http://pinout.xyz/)
|
data/config/config.yaml
CHANGED
data/lib/route_c/cli.rb
CHANGED
@@ -43,7 +43,7 @@ module RouteC
|
|
43
43
|
end
|
44
44
|
|
45
45
|
print 'Waiting for you to push the button... '
|
46
|
-
PiPiper.watch pin:
|
46
|
+
PiPiper.watch pin: config.button do
|
47
47
|
RouteC::CLI.new.watching
|
48
48
|
end
|
49
49
|
|
@@ -54,7 +54,7 @@ module RouteC
|
|
54
54
|
def watching
|
55
55
|
puts 'done'
|
56
56
|
print 'Getting data... '
|
57
|
-
routec = RouteC::Query.new
|
57
|
+
routec = RouteC::Query.new config.station, config.direction
|
58
58
|
puts 'done'
|
59
59
|
|
60
60
|
print 'Lighting lights... '
|
@@ -67,6 +67,10 @@ module RouteC
|
|
67
67
|
|
68
68
|
print 'Waiting for you to push the button... '
|
69
69
|
end
|
70
|
+
|
71
|
+
def config
|
72
|
+
@config ||= Config.new
|
73
|
+
end
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RouteC
|
2
|
+
class Config
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@config = fetch_yaml "#{gem_dir}/config.yaml"
|
6
|
+
|
7
|
+
if File.exists? "#{user_dir}/config.yaml"
|
8
|
+
@local = fetch_yaml "#{user_dir}/config.yaml"
|
9
|
+
@config.merge! @local
|
10
|
+
end
|
11
|
+
|
12
|
+
@config.each do |k,v|
|
13
|
+
self.class.send(:define_method, k.to_sym, Proc.new { return v })
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_yaml file
|
18
|
+
YAML.load_file file
|
19
|
+
end
|
20
|
+
|
21
|
+
def user_dir
|
22
|
+
File.join(ENV['HOME'], '.routec')
|
23
|
+
end
|
24
|
+
|
25
|
+
def gem_dir
|
26
|
+
File.join(File.dirname(__FILE__), '..', '..', 'config')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/route_c/lights.rb
CHANGED
@@ -2,34 +2,26 @@ module RouteC
|
|
2
2
|
class Lights
|
3
3
|
|
4
4
|
def initialize(array)
|
5
|
-
@array = array
|
5
|
+
@array, @config = array, Config.new
|
6
6
|
end
|
7
7
|
|
8
8
|
def turn_on
|
9
9
|
@array.each_with_index do |b, i|
|
10
10
|
if b == 1
|
11
11
|
lights[i].on
|
12
|
-
sleep
|
12
|
+
sleep @config.interval
|
13
13
|
end
|
14
14
|
end
|
15
|
-
sleep
|
16
|
-
lights.reverse.each { |l| l.off ; sleep
|
15
|
+
sleep @config.pause
|
16
|
+
lights.reverse.each { |l| l.off ; sleep @config.interval }
|
17
17
|
end
|
18
18
|
|
19
19
|
def lights
|
20
|
-
@lights ||=
|
20
|
+
@lights ||= @config.lights.map { |p| PiPiper::Pin.new(pin: p, direction: :out) }
|
21
21
|
end
|
22
22
|
|
23
23
|
def release
|
24
24
|
lights.map { |l| l.release }
|
25
25
|
end
|
26
|
-
|
27
|
-
def self.pins
|
28
|
-
YAML.load_file('config/pins.yaml')['lights']
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.button
|
32
|
-
YAML.load_file('config/pins.yaml')['button']
|
33
|
-
end
|
34
26
|
end
|
35
27
|
end
|
data/lib/route_c/query.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module RouteC
|
2
2
|
class Query
|
3
3
|
def initialize(station, direction, datetime = nil)
|
4
|
-
@station, @direction, @datetime = station, direction, set_datetime(datetime)
|
4
|
+
@station, @direction, @datetime, @config = station, direction, set_datetime(datetime), Config.new
|
5
5
|
end
|
6
6
|
|
7
7
|
def set_datetime(datetime)
|
@@ -15,11 +15,7 @@ module RouteC
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def url
|
18
|
-
"#{
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.config
|
22
|
-
YAML.load_file 'config/config.yaml'
|
18
|
+
"#{@config.base_url}#{@direction}/#{@station}/#{@datetime}.json"
|
23
19
|
end
|
24
20
|
|
25
21
|
def json
|
@@ -36,13 +32,13 @@ module RouteC
|
|
36
32
|
average.round
|
37
33
|
end
|
38
34
|
|
39
|
-
def self.num_elements average, elements =
|
35
|
+
def self.num_elements average, elements = Config.new.lights.count
|
40
36
|
(elements * (average / 100.0)).round
|
41
37
|
end
|
42
38
|
|
43
39
|
def to_a
|
44
40
|
num = Query.num_elements average_occupancy
|
45
|
-
Array.new(
|
41
|
+
Array.new(@config.lights.count).each_with_index.map { |k,v| v + 1 <= num ? 1 : 0 }
|
46
42
|
end
|
47
43
|
|
48
44
|
def to_lights
|
data/lib/route_c/version.rb
CHANGED
data/lib/route_c.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: route_c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pikesley
|
@@ -183,7 +183,6 @@ files:
|
|
183
183
|
- bin/console
|
184
184
|
- bin/setup
|
185
185
|
- config/config.yaml
|
186
|
-
- config/pins.yaml
|
187
186
|
- exe/routec
|
188
187
|
- fixtures/rspec/vcr/RouteC_CLI/lights_lights_on_button_press.yml
|
189
188
|
- fixtures/rspec/vcr/RouteC_CLI/lights_the_lights.yml
|
@@ -194,6 +193,7 @@ files:
|
|
194
193
|
- fixtures/rspec/vcr/RouteC_Query/lights_the_lights.yml
|
195
194
|
- lib/route_c.rb
|
196
195
|
- lib/route_c/cli.rb
|
196
|
+
- lib/route_c/config.rb
|
197
197
|
- lib/route_c/lights.rb
|
198
198
|
- lib/route_c/query.rb
|
199
199
|
- lib/route_c/version.rb
|