Class: Ruboty::Handlers::ToggleSwitch
- Inherits:
-
Base
- Object
- Base
- Ruboty::Handlers::ToggleSwitch
- Defined in:
- lib/ruboty/handlers/toggle_switch.rb
Constant Summary collapse
- NAMESPACE =
'toggle_switch'
Instance Method Summary collapse
Instance Method Details
#list(message) ⇒ Object
53 54 55 56 57 |
# File 'lib/ruboty/handlers/toggle_switch.rb', line 53 def list() storage.each do |key, record| .reply("- #{key} is #{record.state}.") end end |
#show(message) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruboty/handlers/toggle_switch.rb', line 39 def show() switch = [:switch] if (record = storage[switch]) text = "#{switch} is #{record.state} " text << "by #{record.from} " if record.from text << "#{record.note} " if record.note text << record.at.strftime('on %b %d at %H:%M') text << '.' .reply(text) end end |
#toggle(message) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruboty/handlers/toggle_switch.rb', line 24 def toggle() switch = [:switch] state = [:state] note = [:note] storage_state = storage[switch] && storage[switch].state if storage_state == state .reply("#{switch} is already #{state}.") else storage[switch] = { state: state, from: .from_name, note: note } .reply("#{switch} is now #{state}.") end end |