Class: Ruboty::ToggleSwitch::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/toggle_switch/storage.rb

Defined Under Namespace

Classes: Record

Constant Summary collapse

NAMESPACE =
'ruboty-toggle_switch-storage'

Instance Method Summary collapse

Constructor Details

#initialize(brain) ⇒ Storage

Returns a new instance of Storage.



8
9
10
# File 'lib/ruboty/toggle_switch/storage.rb', line 8

def initialize(brain)
  @brain = brain
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/ruboty/toggle_switch/storage.rb', line 12

def [](key)
  records[key]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/ruboty/toggle_switch/storage.rb', line 16

def []=(key, value)
  records[key] = Record.new(value[:state], value[:from], Time.now, value[:note])
end

#off?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ruboty/toggle_switch/storage.rb', line 24

def off?(key)
  state_for(key) == 'off'
end

#on?(key) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ruboty/toggle_switch/storage.rb', line 20

def on?(key)
  state_for(key) == 'on'
end