Class: MetricFu::Flog::Page

Inherits:
Base::Generator show all
Defined in:
lib/metric_fu/flog.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(score, scanned_methods = []) ⇒ Page

Returns a new instance of Page.



77
78
79
80
# File 'lib/metric_fu/flog.rb', line 77

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

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



75
76
77
# File 'lib/metric_fu/flog.rb', line 75

def filename
  @filename
end

#scanned_methodsObject

Returns the value of attribute scanned_methods.



75
76
77
# File 'lib/metric_fu/flog.rb', line 75

def scanned_methods
  @scanned_methods
end

#scoreObject

Returns the value of attribute score.



75
76
77
# File 'lib/metric_fu/flog.rb', line 75

def score
  @score
end

Instance Method Details

#average_scoreObject



90
91
92
93
94
95
96
97
# File 'lib/metric_fu/flog.rb', line 90

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



99
100
101
102
103
# File 'lib/metric_fu/flog.rb', line 99

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

#pathObject



82
83
84
# File 'lib/metric_fu/flog.rb', line 82

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

#template_nameObject



105
106
107
# File 'lib/metric_fu/flog.rb', line 105

def template_name
  'flog_page'
end

#to_htmlObject



86
87
88
# File 'lib/metric_fu/flog.rb', line 86

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