class Tailor::Formatters::Yaml

Attributes

accepts_output_file[R]

Public Class Methods

new() click to toggle source
Calls superclass method Tailor::Formatter::new
# File lib/tailor/formatters/yaml.rb, line 10
def initialize
  @accepts_output_file = true
  super
end

Public Instance Methods

summary_report(report) click to toggle source

Prints the report on all of the files that just got checked.

@param [Hash] report Values are filenames; keys are problems for each

of those files.
# File lib/tailor/formatters/yaml.rb, line 19
def summary_report(report)
  build_hash(report).to_yaml
end

Private Instance Methods

build_hash(report) click to toggle source

@param [Hash] report The list of problems found by Tailor::CLI. @return [Hash] The Hash of problems to be converted to YAML.

# File lib/tailor/formatters/yaml.rb, line 27
def build_hash(report)
  report.reject! { |_, v| v.empty? }

  report.inject({}) do |result, problem_set|
    file_name = problem_set.first
    problems = problem_set.last

    problems.each do |problem|
      result[file_name] ||= []

      result[file_name] << {
        type: problem[:type],
        line: problem[:line],
        column: problem[:column],
        message: problem[:message],
        level: problem[:level]
      }
    end

    result
  end
end