class Fukuzatsu::Parser

Constants

DEFAULT_OUTPUT_DIRECTORY

Attributes

formatter[R]
output_path[R]
paths_to_files[R]
threshold[R]

Public Class Methods

new(paths_to_files, formatter, threshold, output_path=nil) click to toggle source
# File lib/fukuzatsu/parser.rb, line 8
def initialize(paths_to_files, formatter, threshold, output_path=nil)
  @paths_to_files = paths_to_files
  @formatter = formatter
  @threshold = threshold
  @output_path = output_path || DEFAULT_OUTPUT_DIRECTORY
end

Public Instance Methods

explain() click to toggle source
# File lib/fukuzatsu/parser.rb, line 15
def explain
  puts "Processed #{summaries.count} file(s)."
  puts "Results written to #{output_path}." if formatter.writes_to_file_system?
end
report() click to toggle source
# File lib/fukuzatsu/parser.rb, line 20
def report
  self.formatter.reset_output_directory(output_path)
  self.formatter.index(summaries, output_path)
  summaries.uniq(&:container_name).each do |summary|
    self.formatter.new(summary: summary, base_output_path: self.output_path).export
  end
  unless self.formatter.no_stdout?
    explain
    check_complexity
  end
end

Private Instance Methods

average_complexities() click to toggle source
# File lib/fukuzatsu/parser.rb, line 41
def average_complexities
  average_complexities ||= summaries.map(&:average_complexity)
end
check_complexity() click to toggle source
# File lib/fukuzatsu/parser.rb, line 34
def check_complexity
  return if self.threshold == 0
  return unless complexity_exceeds_threshold?
  puts "Maximum average complexity of #{average_complexities.max} exceeds #{self.threshold.to_f} threshold!"
  exit 1
end
complexity_exceeds_threshold?() click to toggle source
# File lib/fukuzatsu/parser.rb, line 45
def complexity_exceeds_threshold?
  average_complexities.max.to_f > self.threshold.to_f
end
file_reader() click to toggle source
# File lib/fukuzatsu/parser.rb, line 58
def file_reader
  @file_reader ||= Fukuzatsu::FileReader.new(self.paths_to_files)
end
summaries() click to toggle source
# File lib/fukuzatsu/parser.rb, line 49
def summaries
  @summaries ||= file_reader.source_files.map do |source_file|
    Fukuzatsu::Summary.from(
      content: source_file.contents,
      source_file: source_file.filename
    )
  end.flatten
end