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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2I5ZjBmZjIyNDVkZTU0NjViNDI0MjFlOTY1YTc1M2VkNDQzZWM5MQ==
4
+ ZDkwYTg0Y2YwMjNkNTM3NjI0NTQ1NDU1YWM1MDQyZTU4ODIzMjc4Yw==
5
5
  data.tar.gz: !binary |-
6
- YmU3MTljMDk2MGZkZTg2Y2Q4Nzc1MjljMTE2YmEzZTE1NTNkZGIwZA==
6
+ MWRlMzZjNGE4YjFiZWM0ZDg5ZjZjNjNkZjU5ZTM4NGZlZTQ2MTI4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODNiNDQxOGY0MjgyMDNlNWI4YmQ2MmJkYmE0ZDFhODc3NTdkZjdjMGI1Mjgz
10
- YTdlMTljZjY1YWIxYWM5MjJmODM4OGQyNTRhOTI3MWRmYzEwNjEyMTIzYjdk
11
- NDViYTc2OTU0NDgwOWE5YWVlN2NiODQ2ZTRhMTk3NjQ0YzJhZjg=
9
+ OThhZDFhYmM4Njg3MmIwNjE4YTIwN2FmMDdmYzk4ZTc5YWNjNzJiZWI2ZTM4
10
+ MjRjYzMwNTc3MGRmNzc4YjM5YzFkYmNlYTM3YWM1ODhkMmIzZWNiNDYwNjM5
11
+ NGQ4NjA5NTQwZTZkNGUyNWYzNTFmZGI4ODdjMmQwODRhZDNhNzg=
12
12
  data.tar.gz: !binary |-
13
- ZTJkODg1NjY3ZmRlYzVkZTQ1OGJmMTgxOTQ1YTcxZDE4N2VlOThhOGIyZGI3
14
- YjE5NzdjNTJmN2VjMmZlNjgyZjRmNDllYWU0ZmJhMDYzOWYwMThhODcwNjlk
15
- Zjk4MjhhMDAzOTA1YWE5MjExMzBmNzA3MDFjMzVhN2I2NzBlYjQ=
13
+ MTQ1MTFmYzIzOWQ0ZTU3YzM4ZjIyYTkzMjY5ZmY5NzYwZTlkOTI3YzVmMmRi
14
+ ZDE2MzNiM2U5ZTJiODRiODNkZmVhYWE5ZjY4ZmU4ZTIxMzUxODRmZjY1OTkx
15
+ NjAyNTVmYmI1NDU3OTYxM2JhMjRmYTAzNGNlZThlY2RjNWM1M2Y=
data/README.md CHANGED
@@ -4,3 +4,9 @@
4
4
  [![Code Climate](http://img.shields.io/codeclimate/github/TheODI-UD2D/route_c.svg?style=flat-square)](https://codeclimate.com/github/TheODI-UD2D/route_c)
5
5
  [![Gem Version](http://img.shields.io/gem/v/route_c.svg?style=flat-square)](https://rubygems.org/gems/route_c)
6
6
  [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://TheODI-UD2D.mit-license.org)
7
+
8
+ # Crudely-drawn circuit
9
+
10
+ ![How to Pi](http://i.imgur.com/35a4myB.png)
11
+
12
+ You might also need the [Treasure Map](http://pinout.xyz/)
data/config/config.yaml CHANGED
@@ -1,4 +1,16 @@
1
1
  base_url: http://goingunderground.herokuapp.com/stations/arriving/
2
2
  interval: 0.1
3
3
  pause: 1
4
+ lights:
5
+ - 15
6
+ - 18
7
+ - 23
8
+ - 24
9
+ - 25
10
+ - 8
11
+ - 7
12
+ - 12
4
13
 
14
+ button: 21
15
+ station: euston
16
+ direction: southbound
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: Lights.button do
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 'euston', 'southbound'
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
@@ -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 Query.config['interval']
12
+ sleep @config.interval
13
13
  end
14
14
  end
15
- sleep Query.config['pause']
16
- lights.reverse.each { |l| l.off ; sleep Query.config['interval'] }
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 ||= Lights.pins.map { |p| PiPiper::Pin.new(pin: p, direction: :out) }
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
- "#{Query.config['base_url']}#{@direction}/#{@station}/#{@datetime}.json"
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 = Lights.pins.count
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(Lights.pins.count).each_with_index.map { |k,v| v + 1 <= num ? 1 : 0 }
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
@@ -1,3 +1,3 @@
1
1
  module RouteC
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/route_c.rb CHANGED
@@ -7,6 +7,7 @@ require 'pi_piper'
7
7
  Dotenv.load
8
8
 
9
9
  require "route_c/version"
10
+ require "route_c/config"
10
11
  require "route_c/lights"
11
12
  require "route_c/query"
12
13
  require "route_c/cli"
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.1.3
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
data/config/pins.yaml DELETED
@@ -1,11 +0,0 @@
1
- lights:
2
- - 15
3
- - 18
4
- - 23
5
- - 24
6
- - 25
7
- - 8
8
- - 7
9
- - 12
10
-
11
- button: 21