Class: MetricFu::Heckle::Page

Inherits:
Base::Generator show all
Defined in:
lib/metric_fu/heckle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Generator

#generate_html, generate_report, #generate_report, metric_dir, #save_html, #template_file, template_name

Methods included from TemplateHelpers

#cycle, #inline_css, #link_to_filename

Constructor Details

#initialize(content) ⇒ Page

Returns a new instance of Page.



76
77
78
# File 'lib/metric_fu/heckle.rb', line 76

def initialize(content)
  @content = parse(content)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



74
75
76
# File 'lib/metric_fu/heckle.rb', line 74

def content
  @content
end

#filenameObject

Returns the value of attribute filename.



74
75
76
# File 'lib/metric_fu/heckle.rb', line 74

def filename
  @filename
end

#mutationsObject

Returns the value of attribute mutations.



74
75
76
# File 'lib/metric_fu/heckle.rb', line 74

def mutations
  @mutations
end

#scoreObject

Returns the value of attribute score.



74
75
76
# File 'lib/metric_fu/heckle.rb', line 74

def score
  @score
end

Instance Method Details

#average_scoreObject



99
100
101
102
103
104
105
106
# File 'lib/metric_fu/heckle.rb', line 99

def average_score
  return 0 if scanned_methods.length == 0
  sum = 0
  scanned_methods.each do |m|
    sum += m.score
  end
  sum / scanned_methods.length
end

#highest_scoreObject



108
109
110
111
112
# File 'lib/metric_fu/heckle.rb', line 108

def highest_score
  scanned_methods.inject(0) do |highest, m|
    m.score > highest ? m.score : highest
  end
end

#parse(content) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/metric_fu/heckle.rb', line 80

def parse(content)
  split_content = content.split("\n\n")
  method = split_content.shift
  split_content.shift        
  doc = split_content.shift
  split_content.pop
  split_content.pop
  split_content.pop        
  @mutations = split_content
end

#pathObject



91
92
93
# File 'lib/metric_fu/heckle.rb', line 91

def path
  @path ||= File.basename(filename, ".txt") + '.html'
end

#template_nameObject



114
115
116
# File 'lib/metric_fu/heckle.rb', line 114

def template_name
  'heckle_page'
end

#to_htmlObject



95
96
97
# File 'lib/metric_fu/heckle.rb', line 95

def to_html
  ERB.new(File.read(template_file)).result(binding)
end