ruboty-toggle_switch 0.2.1 → 0.3.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: 9c1220d0e943d1deb267ee35a62f685ca718b3c1
4
- data.tar.gz: 2cd9d3eb95a92c74fc6aa8bec36400d4ba55c06d
3
+ metadata.gz: 00df2ae1f51895928885c249dfc1c995eea69daa
4
+ data.tar.gz: bdf49affd58958dfb711a44e653bba3662a3c665
5
5
  SHA512:
6
- metadata.gz: 7d8ba2502e9c6379b6a336a17ffc1fd67d8e15d3ff30492b0c92a0fbb27e6c4e9323f74003035aa3463101f3e5701d093c8e51f8eb18d05c0dfc9d18f66fb4fd
7
- data.tar.gz: 331d5b7c38afb1eb351d2b68bb208e0cf3bb3dc2b0fe85eb8cab173f78548a66db780ac0a017bea3cad9629a2e0e51e51b4244b046951be4e4451dd73d1b9b64
6
+ metadata.gz: cfd311c904ca3e8838a4e6d27bfeb54152bd955416a8785ad2b4e909c97194274520dc940ccc8b07e6e5d2b6ba9b8b1fc5f2ac846bec900a21d71f1a961c2f0e
7
+ data.tar.gz: 4cc42eb682832f119b33287721ea1aa5ee2bb4f9ffaedfa3b3edc661fefa8218fa9f90fcf4865c1c1309f844bc921fd9fc01f394cb91d71ae55a58d8476d4b9b
data/README.md CHANGED
@@ -15,14 +15,14 @@ gem 'ruboty-toggle_switch'
15
15
  ## Usage
16
16
 
17
17
  ```
18
- > ruboty toggle radio switch on
19
- radio switch is now on.
20
- > ruboty show radio switch status
21
- radio switch is on.
22
- > ruboty toggle radio switch off
23
- radio switch is now off.
24
- > ruboty show radio switch status
25
- radio switch is off.
18
+ > ruboty: toggle switch on
19
+ switch is now on.
20
+ > ruboty: show switch status
21
+ switch is on on Apr 27 at 06:29.
22
+ > ruboty: toggle switch off for good sleeping
23
+ switch is now off.
24
+ > ruboty: show switch status
25
+ switch is off for good sleeping on Apr 27 at 06:30.
26
26
  ```
27
27
 
28
28
  ## API
@@ -3,19 +3,20 @@ module Ruboty
3
3
  class ToggleSwitch < Base
4
4
  NAMESPACE = 'toggle_switch'
5
5
 
6
- on(/toggle\s+(?<switch>.*)\s+(?<state>on|off)\z/, name: 'toggle', description: 'Toggle switch')
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
8
 
9
9
  def toggle(message)
10
10
  switch = message[:switch]
11
11
  state = message[:state]
12
+ note = message[:note]
12
13
 
13
14
  storage_state = storage[switch] && storage[switch].state
14
15
 
15
16
  if storage_state == state
16
17
  message.reply("#{switch} is already #{state}.")
17
18
  else
18
- storage[switch] = {state: state, from: message.from_name}
19
+ storage[switch] = {state: state, from: message.from_name, note: note}
19
20
  message.reply("#{switch} is now #{state}.")
20
21
  end
21
22
  end
@@ -24,7 +25,13 @@ module Ruboty
24
25
  switch = message[:switch]
25
26
 
26
27
  if (record = storage[switch])
27
- message.reply("#{switch} is #{record.state} by #{record.from} #{record.at.strftime('on %b %d at %H:%M')}.")
28
+ text = "#{switch} is #{record.state} "
29
+ text << "by #{record.from} " if record.from
30
+ text << "#{record.note} " if record.note
31
+ text << record.at.strftime('on %b %d at %H:%M')
32
+ text << '.'
33
+
34
+ message.reply(text)
28
35
  end
29
36
  end
30
37
 
@@ -1,7 +1,7 @@
1
1
  module Ruboty
2
2
  module ToggleSwitch
3
3
  class Storage
4
- Record = Struct.new(:state, :from, :at)
4
+ Record = Struct.new(:state, :from, :at, :note)
5
5
 
6
6
  NAMESPACE = 'ruboty-toggle_switch-storage'
7
7
 
@@ -14,11 +14,23 @@ module Ruboty
14
14
  end
15
15
 
16
16
  def []=(key, value)
17
- records[key] = Record.new(value[:state], value[:from], Time.now)
17
+ records[key] = Record.new(value[:state], value[:from], Time.now, value[:note])
18
+ end
19
+
20
+ def on?(key)
21
+ state_for(key) == 'on'
22
+ end
23
+
24
+ def off?(key)
25
+ state_for(key) == 'off'
18
26
  end
19
27
 
20
28
  private
21
29
 
30
+ def state_for(key)
31
+ records[key] && records[key].state
32
+ end
33
+
22
34
  def records
23
35
  @brain.data[NAMESPACE] ||= {}
24
36
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module ToggleSwitch
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-toggle_switch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Takai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty