Class: Attractor::BaseReporter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/attractor/reporters/base_reporter.rb

Overview

base reporter

Direct Known Subclasses

ConsoleReporter, HtmlReporter, SinatraReporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calculators:, file_prefix: "", ignores: "", open_browser: true) ⇒ BaseReporter

Returns a new instance of BaseReporter.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/attractor/reporters/base_reporter.rb', line 18

def initialize(calculators:, file_prefix: "", ignores: "", open_browser: true)
  @file_prefix = file_prefix || ""
  @calculators = calculators
  @open_browser = open_browser
  @suggester = Suggester.new

  @watcher = Watcher.new(@file_prefix, ignores, lambda do
    report
  end)
rescue NoMethodError => _e
  raise "There was a problem gathering churn changes"
end

Instance Attribute Details

#file_prefixObject

Returns the value of attribute file_prefix.



13
14
15
# File 'lib/attractor/reporters/base_reporter.rb', line 13

def file_prefix
  @file_prefix
end

#typesObject (readonly)

Returns the value of attribute types.



14
15
16
# File 'lib/attractor/reporters/base_reporter.rb', line 14

def types
  @types
end

#values(type: "rb") ⇒ Object



46
47
48
49
50
51
# File 'lib/attractor/reporters/base_reporter.rb', line 46

def values(type: "rb")
  @values = @calculators[type].calculate
  @values
rescue NoMethodError => _e
  puts "No calculator for type #{type}"
end

Instance Method Details

#renderObject



42
43
44
# File 'lib/attractor/reporters/base_reporter.rb', line 42

def render
  "Attractor"
end

#reportObject



37
38
39
40
# File 'lib/attractor/reporters/base_reporter.rb', line 37

def report
  @suggestions = @suggester.suggest
  @types = @calculators.map { |calc| [calc.first, calc.last.type] }.to_h
end

#suggestions(quantile:, type: "rb") ⇒ Object



31
32
33
34
35
# File 'lib/attractor/reporters/base_reporter.rb', line 31

def suggestions(quantile:, type: "rb")
  @suggester.values = values(type: type)
  @suggestions = @suggester.suggest(quantile)
  @suggestions
end