Class: MetricFu::ReekGrapher

Inherits:
Grapher
  • Object
show all
Defined in:
lib/graphs/reek_grapher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Grapher

require_gruff

Constructor Details

#initializeReekGrapher

Returns a new instance of ReekGrapher.



7
8
9
10
11
# File 'lib/graphs/reek_grapher.rb', line 7

def initialize
  super
  self.reek_count = {}
  self.labels= {}
end

Instance Attribute Details

#labelsObject

Returns the value of attribute labels.



5
6
7
# File 'lib/graphs/reek_grapher.rb', line 5

def labels
  @labels
end

#reek_countObject

Returns the value of attribute reek_count.



5
6
7
# File 'lib/graphs/reek_grapher.rb', line 5

def reek_count
  @reek_count
end

Instance Method Details

#get_metrics(metrics, date) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/graphs/reek_grapher.rb', line 13

def get_metrics(metrics, date)
  counter = self.labels.size
  self.labels.update( { counter => date })
  
  metrics[:reek][:matches].each do |reek_chunk|
    reek_chunk[:code_smells].each do |code_smell|
      # speaking of code smell...
      self.reek_count[code_smell[:type]] = [] if self.reek_count[code_smell[:type]].nil?
      self.reek_count[code_smell[:type]][counter].nil? ? self.reek_count[code_smell[:type]][counter] = 1 : self.reek_count[code_smell[:type]][counter] += 1
    end
  end
end

#graph!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/graphs/reek_grapher.rb', line 26

def graph!
  g = Gruff::Line.new(MetricFu.graph_size)
  g.title = "Reek: code smells"
  g.theme = MetricFu.graph_theme
  g.font = MetricFu.graph_font
  self.reek_count.each_pair do |type, count|
    g.data(type, count)
  end
  g.labels = self.labels
  g.title_font_size = MetricFu.graph_title_font_size
  g.legend_box_size = MetricFu.graph_legend_box_size
  g.legend_font_size = MetricFu.graph_legend_font_size
  g.marker_font_size = MetricFu.graph_marker_font_size
  g.write(File.join(MetricFu.output_directory, 'reek.png'))
end