ruboty-toggle_switch 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00df2ae1f51895928885c249dfc1c995eea69daa
4
- data.tar.gz: bdf49affd58958dfb711a44e653bba3662a3c665
3
+ metadata.gz: 580bf6e33db15308f664caee452443305ef7c62a
4
+ data.tar.gz: 45b97438c8fa479f90585533bf967e7906b242e4
5
5
  SHA512:
6
- metadata.gz: cfd311c904ca3e8838a4e6d27bfeb54152bd955416a8785ad2b4e909c97194274520dc940ccc8b07e6e5d2b6ba9b8b1fc5f2ac846bec900a21d71f1a961c2f0e
7
- data.tar.gz: 4cc42eb682832f119b33287721ea1aa5ee2bb4f9ffaedfa3b3edc661fefa8218fa9f90fcf4865c1c1309f844bc921fd9fc01f394cb91d71ae55a58d8476d4b9b
6
+ metadata.gz: 82aa4cd51bb856c6069176874809f718915018e7a629031d3b37335306ad40f0a49b1d7870af029ca0cdb8441c93062dfb81fec01122c9cc13e1ad3e1e33d803
7
+ data.tar.gz: 1bb763dfe7eff9d94f5b38c1784b2a85540d8feaa77f4236b7fde00c68a9a6249b943aef1c7c2f4bc96891ae9146066cbce4f6f96b4373c3d647e91f409f488c
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
@@ -5,18 +5,19 @@ module Ruboty
5
5
 
6
6
  on(/toggle\s+(?<switch>.*)\s+(?<state>on|off)(?:\s+(?<note>.*))?\z/, name: 'toggle', description: 'Toggle switch')
7
7
  on(/show\s+(?<switch>.*)\s+status\z/, name: 'show', description: 'Show switch status')
8
+ on(/list switches/, name: 'list', description: 'Show list of switches')
8
9
 
9
10
  def toggle(message)
10
11
  switch = message[:switch]
11
- state = message[:state]
12
- note = message[:note]
12
+ state = message[:state]
13
+ note = message[:note]
13
14
 
14
15
  storage_state = storage[switch] && storage[switch].state
15
16
 
16
17
  if storage_state == state
17
18
  message.reply("#{switch} is already #{state}.")
18
19
  else
19
- storage[switch] = {state: state, from: message.from_name, note: note}
20
+ storage[switch] = { state: state, from: message.from_name, note: note }
20
21
  message.reply("#{switch} is now #{state}.")
21
22
  end
22
23
  end
@@ -35,6 +36,12 @@ module Ruboty
35
36
  end
36
37
  end
37
38
 
39
+ def list(message)
40
+ storage.each do |key, record|
41
+ message.reply("- #{key} is #{record.state}.")
42
+ end
43
+ end
44
+
38
45
  private
39
46
 
40
47
  def storage
@@ -1,6 +1,8 @@
1
1
  module Ruboty
2
2
  module ToggleSwitch
3
3
  class Storage
4
+ include Enumerable
5
+
4
6
  Record = Struct.new(:state, :from, :at, :note)
5
7
 
6
8
  NAMESPACE = 'ruboty-toggle_switch-storage'
@@ -25,6 +27,16 @@ module Ruboty
25
27
  state_for(key) == 'off'
26
28
  end
27
29
 
30
+ def each
31
+ records.each do |entry|
32
+ yield(*entry)
33
+ end
34
+ end
35
+
36
+ def size
37
+ records.size
38
+ end
39
+
28
40
  private
29
41
 
30
42
  def state_for(key)
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module ToggleSwitch
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-toggle_switch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Takai