Class: Slk::Commands::Dnd
- Inherits:
-
Base
- Object
- Base
- Slk::Commands::Dnd
show all
- Defined in:
- lib/slk/commands/dnd.rb
Overview
Manages Do Not Disturb (snooze) settings rubocop:disable Metrics/ClassLength
Instance Attribute Summary
Attributes inherited from Base
#options, #positional_args, #runner
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#dispatch_action ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/slk/commands/dnd.rb', line 23
def dispatch_action
case positional_args
in ['status' | 'info'] | [] then get_status
in ['on' | 'snooze', *rest] then enable_snooze(rest.first)
in ['off' | 'end'] then end_snooze
in [duration_str] if duration_str.match?(/^\d+[hms]?$/) then enable_snooze(duration_str)
else unknown_action
end
end
|
#enable_snooze(duration_str) ⇒ Object
33
34
35
36
|
# File 'lib/slk/commands/dnd.rb', line 33
def enable_snooze(duration_str)
duration = Models::Duration.parse(duration_str || '1h')
set_snooze(duration)
end
|
#execute ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/slk/commands/dnd.rb', line 10
def execute
result = validate_options
return result if result
dispatch_action
rescue ArgumentError => e
error("Invalid duration: #{e.message}")
1
rescue ApiError => e
error("Failed: #{e.message}")
1
end
|
#unknown_action ⇒ Object
38
39
40
41
42
|
# File 'lib/slk/commands/dnd.rb', line 38
def unknown_action
error("Unknown action: #{positional_args.first}")
error('Valid actions: status, on, off, or a duration (e.g., 1h)')
1
end
|