module ClockReport
ClockReport โ IRC card formatting for clock ticks and flip-time entries. Public: format_tick, format_flip_entry, format_status, format_voice_status, format_ack Depends: IrcFormat, IrcReply, ClockCondense Tests: test/lib/clock_report_test.rb
Constants
- STYLE_TITLE
- TIME_HELP_LABEL
Public Instance Methods
Source
# File lib/clock/report.rb, line 139 def format_ack(enabled:, lines:) if enabled format_status(enabled: true, lines: lines) else format_status(enabled: false, lines: lines) end end
Source
# File lib/clock/report.rb, line 80 def format_flip_entry(time_label:, flip_word:, lines:, source:, title_suffix: nil) title = [time_label, "flip #{flip_word}"] title << title_suffix if title_suffix && !title_suffix.to_s.strip.empty? body = Array(lines).map { |line| ClockCondense.condense_line(line) }.reject(&:empty?) IrcReply.card( tag: "TIME", title: title.join(" ยท "), body_lines: body, footer_parts: [source_label(source)], heading_style: STYLE_TITLE ) end
Source
# File lib/clock/report.rb, line 57 def format_single_line_tick(header:, assoc_plain:, led_body:, led_lines:, association_lines:, time_label:) meaning_line = assoc_plain.first first_line = tick_header_with_suffix(header, meaning_line) if meaning_line first_line ||= header if meaning_line [first_line] + led_body else [first_line] + ClockCondense.tick_body_lines( led_lines: led_lines, association_lines: association_lines, time_label: time_label ) end end
Source
# File lib/clock/report.rb, line 105 def format_status(enabled:, lines:, require_voice: true) state_label = enabled ? "on" : "off" detail = enabled ? "#{lines} LED #{lines == 1 ? 'line' : 'lines'}" : "every minute off" voice_label = require_voice ? "voice on" : "voice off" IrcReply.card( tag: "CLOCK", title: "#{state_label} ยท #{detail} ยท #{voice_label}", body_lines: [ enabled ? "Announcing time and upside-down words each minute." : "Clock announcements disabled." ], footer_parts: ["!clock on|off", "1โ20 lines", "!clock voice on|off"], heading_style: STYLE_TITLE ) end
Source
# File lib/clock/report.rb, line 18 def format_tick(time_label:, tz_label:, flip_word:, led_lines:, association_lines:, meaning_hint: nil, line_budget: 1) title_parts = [time_label.to_s.strip] title_parts << tz_label.to_s.strip unless tz_label.to_s.strip.empty? flip = flip_word.to_s.strip title_parts << flip.upcase unless flip.empty? title_parts << TIME_HELP_LABEL budget = [line_budget.to_i, 1].max assoc_plain = Array(association_lines) .map { |line| ClockCondense.full_line(line) } .reject(&:empty?) led_body = ClockCondense.tick_led_body_lines(led_lines: led_lines, time_label: time_label) header = IrcFormat.report_header(tag: "CLOCK", title: IrcFormat.meta_join(*title_parts), style: STYLE_TITLE) if ClockCondense.bare_tick?(led_lines: led_lines, association_lines: association_lines, time_label: time_label) return header end content_lines = if budget > 1 && !assoc_plain.empty? [header] + assoc_plain elsif budget == 1 format_single_line_tick(header: header, assoc_plain: assoc_plain, led_body: led_body, led_lines: led_lines, association_lines: association_lines, time_label: time_label) else [header] + ClockCondense.tick_body_lines( led_lines: led_lines, association_lines: association_lines, time_label: time_label ) end hint = meaning_hint.to_s.strip footer = hint.empty? ? nil : IrcFormat.report_footer(hint) content_lines << footer unless footer.to_s.strip.empty? content_lines.join("\n") end
Source
# File lib/clock/report.rb, line 121 def format_voice_status(require_voice:) label = require_voice ? "on" : "off" IrcReply.card( tag: "CLOCK", title: "voice #{label}", body_lines: [ if require_voice "Ticks need +v or +o on moderated (+m) channels." else "Ticks post without a voice/op check." end ], footer_parts: ["!clock voice on|off"], heading_style: STYLE_TITLE ) end
Source
# File lib/clock/report.rb, line 95 def source_label(source) case source.to_s when "manual" then "manual entry" when "wordnet" then "WordNet" when "urban" then "Urban Dictionary" when "wiki" then "Wikipedia" else source.to_s end end
Source
# File lib/clock/report.rb, line 75 def tick_header_with_suffix(header, suffix) suffix = suffix.to_s.strip suffix.empty? ? header : "#{header} #{suffix}" end