Class: Gry::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gry/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(display_disabled_cops:) ⇒ Formatter

Returns a new instance of Formatter.



3
4
5
# File 'lib/gry/formatter.rb', line 3

def initialize(display_disabled_cops:)
  @display_disabled_cops = display_disabled_cops
end

Instance Method Details

#format(laws) ⇒ String

Returns a yaml string.

Parameters:

  • gry_result (Array<Law>)

Returns:

  • (String)

    a yaml string



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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