Class: MetricFu::FlogReporter::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Generator

#generate_html, #generate_report, generate_report, #link_to_filename, #save_html, #template_file

Constructor Details

#initialize(score, scanned_methods = []) ⇒ Page

Returns a new instance of Page.



5
6
7
8
# File 'lib/metric_fu/flog_reporter/page.rb', line 5

def initialize(score, scanned_methods = [])
  @score = score.to_f
  @scanned_methods = scanned_methods
end

Instance Attribute Details

#scanned_methodsObject

Returns the value of attribute scanned_methods.



3
4
5
# File 'lib/metric_fu/flog_reporter/page.rb', line 3

def scanned_methods
  @scanned_methods
end

#scoreObject

Returns the value of attribute score.



3
4
5
# File 'lib/metric_fu/flog_reporter/page.rb', line 3

def score
  @score
end

Instance Method Details

#average_scoreObject



14
15
16
17
18
19
20
# File 'lib/metric_fu/flog_reporter/page.rb', line 14

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

#highest_scoreObject



22
23
24
25
26
# File 'lib/metric_fu/flog_reporter/page.rb', line 22

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

#template_nameObject

should be dynamically read from the class



29
30
31
# File 'lib/metric_fu/flog_reporter/page.rb', line 29

def template_name
  'flog_page'
end

#to_htmlObject



10
11
12
# File 'lib/metric_fu/flog_reporter/page.rb', line 10

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