module IrcReply
Compose Ibis-style IRC reply cards: Β«TAGΒ», -=// title \=-, plain body, accent_paren footer.
Public Instance Methods
Source
# File lib/irc_reply.rb, line 10 def card(tag:, title:, body_lines: [], footer_parts: nil, heading_style: nil, palette: nil, frame: :none) heading_style ||= palette_heading_style(palette) || IrcFormat.menu_heading_style lines = [] lines.concat(frame_lines(frame, palette: palette)) lines << IrcFormat.report_header(tag: tag, title: title, style: heading_style) Array(body_lines).each do |line| text = line.to_s lines << text unless text.strip.empty? end footer = footer_parts.nil? ? nil : IrcFormat.report_footer(*Array(footer_parts)) lines << footer unless footer.to_s.strip.empty? lines.join("\n") end
Source
# File lib/irc_reply.rb, line 24 def error(tag:, message:, heading_style: nil, palette: nil) card( tag: tag, title: "error", body_lines: [message.to_s.strip], heading_style: heading_style, palette: palette ) end
Source
# File lib/irc_reply.rb, line 44 def frame_lines(frame, palette: nil) case frame when :ibis_line line = IrcAscii.degree_line(width: 40) [IrcFormat.decorate(line, IrcFormat.named_style(:accent))] when :fserve rule = "+" + ("-" * 38) + "+" [IrcFormat.decorate(rule, IrcFormat.named_style(:tag))] else [] end end
Source
# File lib/irc_reply.rb, line 34 def palette_heading_style(palette) return nil unless palette pair = Array(palette[:title] || palette["title"]) return nil if pair.empty? pair.length == 2 ? IrcFormat.color(pair[0], pair[1]) : IrcFormat.color(pair[0]) end