Class: MetricFu::Heckle::Page
- Inherits:
-
Base::Generator
- Object
- Base::Generator
- MetricFu::Heckle::Page
- Defined in:
- lib/metric_fu/heckle.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#mutations ⇒ Object
Returns the value of attribute mutations.
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
- #average_score ⇒ Object
- #highest_score ⇒ Object
-
#initialize(content) ⇒ Page
constructor
A new instance of Page.
- #parse(content) ⇒ Object
- #path ⇒ Object
- #template_name ⇒ Object
- #to_html ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
74 75 76 |
# File 'lib/metric_fu/heckle.rb', line 74 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
74 75 76 |
# File 'lib/metric_fu/heckle.rb', line 74 def filename @filename end |
#mutations ⇒ Object
Returns the value of attribute mutations.
74 75 76 |
# File 'lib/metric_fu/heckle.rb', line 74 def mutations @mutations end |
#score ⇒ Object
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_score ⇒ Object
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_score ⇒ Object
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 |
#path ⇒ Object
91 92 93 |
# File 'lib/metric_fu/heckle.rb', line 91 def path @path ||= File.basename(filename, ".txt") + '.html' end |
#template_name ⇒ Object
114 115 116 |
# File 'lib/metric_fu/heckle.rb', line 114 def template_name 'heckle_page' end |
#to_html ⇒ Object
95 96 97 |
# File 'lib/metric_fu/heckle.rb', line 95 def to_html ERB.new(File.read(template_file)).result(binding) end |