class Unused::Reporters::StdoutReporter

Constants

HEADERS

Public Class Methods

new(instance_methods, class_methods, map) click to toggle source
# File lib/unused/reporters/stdout_reporter.rb, line 15
def initialize(instance_methods, class_methods, map)
  @instance_methods = instance_methods
  @class_methods = class_methods
  @map = map
end

Public Instance Methods

output() click to toggle source
# File lib/unused/reporters/stdout_reporter.rb, line 25
def output
  method_length, call_length, loc_length = column_lengths
  data = output_data
  output = ''
  output += HEADERS[0].ljust(method_length, ' ') + "\t"
  output += HEADERS[1].ljust(call_length, ' ') + "\t"
  output += HEADERS[2].ljust(loc_length, ' ') + "\t"
  output += "\n"

  data.each do |method, calls, location|
    output += method.ljust(method_length, ' ') + "\t"
    output += calls.rjust(call_length, ' ') + "\t"
    output += location.ljust(loc_length, ' ') + "\t"
    output += "\n"
  end

  output
end
report() click to toggle source
# File lib/unused/reporters/stdout_reporter.rb, line 21
def report
  print(output)
end

Private Instance Methods

column_lengths() click to toggle source
# File lib/unused/reporters/stdout_reporter.rb, line 54
def column_lengths
  output_data.transpose.map.with_index do |values, index|
    [
      HEADERS[index].length,
      values.map(&:length).max
    ].max
  end
end
output_data() click to toggle source
# File lib/unused/reporters/stdout_reporter.rb, line 46
def output_data
  unused_methods.map do |method|
    [method.representation,
     method.calls.to_s,
     method.source]
  end
end
unused_methods() click to toggle source
# File lib/unused/reporters/stdout_reporter.rb, line 63
def unused_methods
  method_summary.select do |method|
    method.calls.zero?
  end
end