Class: Ruboty::ToggleSwitch::Storage
- Inherits:
-
Object
- Object
- Ruboty::ToggleSwitch::Storage
- Includes:
- Enumerable
- Defined in:
- lib/ruboty/toggle_switch/storage.rb
Defined Under Namespace
Classes: Switch
Constant Summary collapse
- NAMESPACE =
'ruboty-toggle_switch-storage'
Instance Method Summary collapse
-
#[](key) ⇒ Switch?
Returns the switch to which the specified key is mapped.
-
#[]=(key, value) ⇒ Object
Update the switch which is associated with the specified key.
-
#each ⇒ Object
Yields each pair of the key and switch.
-
#initialize(brain) ⇒ Storage
constructor
Returns a new instance of Storage.
-
#off?(key) ⇒ Boolean
Returns true if the switch is ‘off’.
-
#on?(key) ⇒ Boolean
Returns true if the switch is ‘on’.
Constructor Details
#initialize(brain) ⇒ Storage
Returns a new instance of Storage
13 14 15 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 13 def initialize(brain) @brain = brain end |
Instance Method Details
#[](key) ⇒ Switch?
Returns the switch to which the specified key is mapped.
20 21 22 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 20 def [](key) switches[key] end |
#[]=(key, value) ⇒ Object
Update the switch which is associated with the specified key.
30 31 32 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 30 def []=(key, value) switches[key] = Switch.new(value[:state], value[:from], Time.now, value[:note]) end |
#each ⇒ Object
Yields each pair of the key and switch.
49 50 51 52 53 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 49 def each switches.each do |entry| yield(*entry) end end |
#off?(key) ⇒ Boolean
Returns true if the switch is ‘off’.
44 45 46 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 44 def off?(key) state_for(key) == 'off' end |
#on?(key) ⇒ Boolean
Returns true if the switch is ‘on’.
37 38 39 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 37 def on?(key) state_for(key) == 'on' end |