Class: Slk::Formatters::JsonStatusFormatter
- Inherits:
-
Object
- Object
- Slk::Formatters::JsonStatusFormatter
- Defined in:
- lib/slk/formatters/json_status_formatter.rb
Overview
Renders slk status snapshots as JSON for scripts and statuslines.
Two shape rules the consumers depend on:
- Always an array, one entry per workspace, even for a single one. The
workspace set changes with -w/--all, and a document whose shape
changes with a flag cannot be parsed by a script that did not pass it.
- null means "not checked" (skipped, or the lookup failed); an empty
array or false means checked. A statusline that treats a failed DND
lookup as "DND off" would quietly say the opposite of the truth.
Timestamps appear twice: the raw Slack epoch under Slack's own field name and an ISO 8601 string beside it, so neither jq nor the shell has to do date arithmetic to print "until 3:00pm".
Instance Method Summary collapse
- #format(snapshots) ⇒ Object
-
#format_scheduled(by_workspace) ⇒ Object
slk status scheduled --json: the same array, narrowed to the part that command is about, so a script can read either with one shape.
Instance Method Details
#format(snapshots) ⇒ Object
22 23 24 |
# File 'lib/slk/formatters/json_status_formatter.rb', line 22 def format(snapshots) snapshots.map { |snapshot| snapshot_hash(snapshot) } end |
#format_scheduled(by_workspace) ⇒ Object
slk status scheduled --json: the same array, narrowed to the part
that command is about, so a script can read either with one shape.
30 31 32 33 34 |
# File 'lib/slk/formatters/json_status_formatter.rb', line 30 def format_scheduled(by_workspace) by_workspace.map do |name, scheduled| { workspace: name, scheduled: scheduled&.map { |status| scheduled_hash(status) } } end end |