lib/recog/formatter.rb in recog-3.1.1 vs lib/recog/formatter.rb in recog-3.1.2

- old
+ new

@@ -1,51 +1,53 @@ +# frozen_string_literal: true + module Recog -class Formatter - COLORS = { - :red => 31, - :yellow => 33, - :green => 32, - :white => 15 - } + class Formatter + COLORS = { + red: 31, + yellow: 33, + green: 32, + white: 15 + }.freeze - attr_reader :options, :output + attr_reader :options, :output - def initialize(options, output) - @options = options - @output = output || StringIO.new - end + def initialize(options, output) + @options = options + @output = output || StringIO.new + end - def status_message(text) - output.puts color(text, :white) - end + def status_message(text) + output.puts color(text, :white) + end - def success_message(text) - output.puts color(text, :green) - end + def success_message(text) + output.puts color(text, :green) + end - def warning_message(text) - output.puts color(text, :yellow) - end + def warning_message(text) + output.puts color(text, :yellow) + end - def failure_message(text) - output.puts color(text, :red) - end + def failure_message(text) + output.puts color(text, :red) + end - private + private - def color_enabled? - options.color - end + def color_enabled? + options.color + end - def color(text, color_code) - color_enabled? ? colorize(text, color_code) : text - end + def color(text, color_code) + color_enabled? ? colorize(text, color_code) : text + end - def colorize(text, color_code) - "\e[#{color_code_for(color_code)}m#{text}\e[0m" - end + def colorize(text, color_code) + "\e[#{color_code_for(color_code)}m#{text}\e[0m" + end - def color_code_for(code) - COLORS.fetch(code) { COLORS.fetch(:white) } + def color_code_for(code) + COLORS.fetch(code) { COLORS.fetch(:white) } + end end -end end