ruboty-toggle_switch 0.2.1 → 0.3.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 +4 -4
 - data/README.md +8 -8
 - data/lib/ruboty/handlers/toggle_switch.rb +10 -3
 - data/lib/ruboty/toggle_switch/storage.rb +14 -2
 - data/lib/ruboty/toggle_switch/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 00df2ae1f51895928885c249dfc1c995eea69daa
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bdf49affd58958dfb711a44e653bba3662a3c665
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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  
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            > ruboty show  
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            > ruboty toggle  
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            > ruboty show  
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 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) 
     | 
| 
      
 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 
     | 
    
         
            -
                       
     | 
| 
      
 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
         
     | 
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-04-27 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: ruboty
         
     |