module BannerReport
BannerReport โ IRC block-letter banners with optional subheading rows. Public: format_command, format_reply Depends: BannerFont, BannerParse, BannerEngines, BannerEngineRunner, IrcFormat, IrcReply Tests: test/lib/banner_report_test.rb, test/plugins/banner_test.rb
Constants
- REPLY_TAG
- STYLE_TITLE
- SUB_STYLES
Public Instance Methods
Source
# File lib/banner_report.rb, line 90 def art_rows(heading, engine_picker:, runner:, glyphs: nil, engine_option: nil) id = engine_picker.call block_glyphs = id == :blocks ? glyphs : nil result = runner.render(id, heading, glyphs: block_glyphs, engine_option: engine_option) if result[:error] result = runner.render(:blocks, heading, glyphs: glyphs) id = :blocks engine_option = nil end { id: id, lines: result[:lines], option_label: engine_option&.fetch(:label) } end
Source
# File lib/banner_report.rb, line 83 def error_result(message) { error: true, reply: IrcReply.error(tag: REPLY_TAG, message: message, heading_style: STYLE_TITLE) } end
Source
# File lib/banner_report.rb, line 36 def format_command(args, engine_picker: nil, runner: BannerEngineRunner, network: nil, channel: nil, store: RabbotDb, rng: Random) parsed = BannerParse.parse(args) return error_result(parsed[:error]) if parsed[:error] picker = engine_picker || BannerEnginePick.picker_for(parsed[:engine]) engine_option = parsed[:engine] ? BannerEngineOptions.pick(parsed[:engine], rng: rng) : nil { error: false, reply: format_reply( parsed, engine_picker: picker, runner: runner, network: network, channel: channel, store: store, engine_option: engine_option ) } end
Source
# File lib/banner_report.rb, line 57 def format_reply(parsed, engine_picker:, runner:, network: nil, channel: nil, store: RabbotDb, engine_option: nil) style = title_style(fg: parsed[:title_fg], bg: parsed[:title_bg]) lines = [] lines << IrcFormat.report_header(tag: REPLY_TAG, title: parsed[:heading], style: style) glyphs = glyphs_for_channel(network: network, channel: channel, store: store) art = art_rows(parsed[:heading], engine_picker: engine_picker, runner: runner, glyphs: glyphs, engine_option: engine_option) colour_art = parsed.key?(:title_fg) || art[:id] == :blocks art[:lines].each do |row| line = colour_art ? IrcFormat.decorate(row, style) : row lines << line end parsed[:subheadings].each_with_index do |sub, index| style = SUB_STYLES[index % SUB_STYLES.length] label = IrcFormat.decorate(sub[:label], style) body = sub[:body].to_s line = body.empty? ? label : "#{label}#{IrcFormat::RESET} โ #{body}" lines << line end footer = IrcFormat.report_footer(footer_label(art[:id], art[:option_label]), "banner") lines << footer unless footer.to_s.strip.empty? lines.join("\n") end
Source
# File lib/banner_report.rb, line 107 def glyphs_for_channel(network:, channel:, store: RabbotDb) return nil if network.to_s.strip.empty? || channel.to_s.strip.empty? BannerFontStore.effective_glyphs(network: network, channel: channel, store: store) end
Source
# File lib/banner_report.rb, line 29 def title_style(fg: nil, bg: nil) return STYLE_TITLE if fg.nil? && bg.nil? return IrcFormat.color(fg) if bg.nil? IrcFormat.color(fg, bg) end