module PaintAnalyse
PaintAnalyse — validate theme paint_rules against registered PaintSamples lines. Public: analyse Depends: IrcFormat, IrcPaint, PaintSamples Tests: test/lib/paint_analyse_test.rb
Public Instance Methods
Source
# File lib/paint_analyse.rb, line 15 def analyse(theme) rules = Array(theme[:paint_rules]) theme_id = theme[:id].to_s theme_name = theme[:name].to_s if rules.empty? return { theme_id: theme_id, theme_name: theme_name, findings: [{ status: :warn, detail: "no paint rules to validate" }], counts: { ok: 0, warn: 1, error: 0 } } end findings = rules.map { |rule| validate_rule(rule) } counts = { ok: 0, warn: 0, error: 0 } findings.each { |entry| counts[entry[:status]] += 1 } { theme_id: theme_id, theme_name: theme_name, findings: findings, counts: counts } end
Source
# File lib/paint_analyse.rb, line 79 def format_command(rule) colour = rule[:bg] ? "#{rule[:fg]},#{rule[:bg]}" : rule[:fg].to_s "!paint #{rule[:plugin]} #{rule[:line]} #{rule[:pos]} #{colour}" end
Source
# File lib/paint_analyse.rb, line 41 def validate_rule(rule) plugin = rule[:plugin].to_s line_number = rule[:line].to_i pos = rule[:pos].to_i fg = rule[:fg] bg = rule[:bg] base = { plugin: plugin, line: line_number, pos: pos, command: format_command(rule) } unless IrcFormat.valid_color?(fg) return base.merge(status: :error, detail: "invalid colour fg=#{fg}") end if bg && !IrcFormat.valid_color?(bg) return base.merge(status: :error, detail: "invalid colour bg=#{bg}") end lines = PaintSamples.lines(plugin) return base.merge(status: :error, detail: "unknown plugin — try !paint list") unless lines if line_number < 1 || line_number > lines.length return base.merge(status: :error, detail: "line out of range (1-#{lines.length})") end line_text = lines[line_number - 1] block = IrcPaint.block_at_plain_index(line_text, pos) unless block return base.merge(status: :error, detail: "no colour block at position #{pos}") end span = block[:text].to_s base.merge(status: :ok, detail: span.empty? ? "block at #{pos}" : span) end