class Gry::Formatter
Public Class Methods
new(display_disabled_cops:)
click to toggle source
# File lib/gry/formatter.rb, line 3 def initialize(display_disabled_cops:) @display_disabled_cops = display_disabled_cops end
Public Instance Methods
format(laws)
click to toggle source
@param gry_result [Array<Law>] @return [String] a yaml string
# File lib/gry/formatter.rb, line 9 def format(laws) confs = laws.map do |law| if law.letter letter = {law.name => law.letter} else if @display_disabled_cops letter = {law.name => {'Enabled' => false}} else next end end comment = RubocopAdapter.metrics_cop?(law.name) ? '' : to_comment(law.bill) yaml = to_yaml(letter) comment + yaml end.compact to_yaml(RubocopAdapter.config_base) + "\n" + confs.join("\n") end
Private Instance Methods
offenses(count)
click to toggle source
# File lib/gry/formatter.rb, line 51 def offenses(count) if count > 1 'offenses' else 'offense' end end
to_comment(set_count)
click to toggle source
# File lib/gry/formatter.rb, line 39 def to_comment(set_count) set_count.map do |setting, offenses| count = offenses.size x = setting .reject{|key, _| key == 'Enabled'} .map{|key, value| "#{key}: #{value}"} .join(', ') "# #{x} => #{count} #{offenses(count)}\n" end.join end
to_yaml(hash)
click to toggle source
# File lib/gry/formatter.rb, line 35 def to_yaml(hash) YAML.dump(hash)[4..-1] end