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
27 28 29 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 27 def initialize(brain) @brain = brain end |
Instance Method Details
#[](key) ⇒ Switch?
Returns the switch to which the specified key is mapped.
34 35 36 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 34 def [](key) switches[key] end |
#[]=(key, value) ⇒ Object
Update the switch which is associated with the specified key.
44 45 46 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 44 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.
63 64 65 66 67 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 63 def each switches.each do |entry| yield(*entry) end end |
#off?(key) ⇒ Boolean
Returns true if the switch is 'off'.
58 59 60 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 58 def off?(key) state_for(key) == 'off' end |
#on?(key) ⇒ Boolean
Returns true if the switch is 'on'.
51 52 53 |
# File 'lib/ruboty/toggle_switch/storage.rb', line 51 def on?(key) state_for(key) == 'on' end |