Class: FlogBuilder::Page
- Inherits:
-
Object
- Object
- FlogBuilder::Page
- Defined in:
- lib/flog_builder.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#scanned_methods ⇒ Object
Returns the value of attribute scanned_methods.
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
- #average_score ⇒ Object
- #highest_score ⇒ Object
-
#initialize(score, scanned_methods = []) ⇒ Page
constructor
A new instance of Page.
- #path ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(score, scanned_methods = []) ⇒ Page
Returns a new instance of Page.
13 14 15 16 |
# File 'lib/flog_builder.rb', line 13 def initialize(score, scanned_methods = []) @score = score.to_f @scanned_methods = scanned_methods end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/flog_builder.rb', line 11 def filename @filename end |
#scanned_methods ⇒ Object
Returns the value of attribute scanned_methods.
11 12 13 |
# File 'lib/flog_builder.rb', line 11 def scanned_methods @scanned_methods end |
#score ⇒ Object
Returns the value of attribute score.
11 12 13 |
# File 'lib/flog_builder.rb', line 11 def score @score end |
Instance Method Details
#average_score ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/flog_builder.rb', line 26 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
35 36 37 38 39 |
# File 'lib/flog_builder.rb', line 35 def highest_score scanned_methods.inject(0) do |highest, m| m.score > highest ? m.score : highest end end |
#path ⇒ Object
18 19 20 |
# File 'lib/flog_builder.rb', line 18 def path @path ||= File.basename(filename, ".txt") + '.html' end |
#to_html ⇒ Object
22 23 24 |
# File 'lib/flog_builder.rb', line 22 def to_html ERB.new(File.read(File.join(File.dirname(__FILE__), "site/flog_page.html.erb"))).result(binding) end |