Class: FlogBuilder::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/flog_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filenameObject

Returns the value of attribute filename.



11
12
13
# File 'lib/flog_builder.rb', line 11

def filename
  @filename
end

#scanned_methodsObject

Returns the value of attribute scanned_methods.



11
12
13
# File 'lib/flog_builder.rb', line 11

def scanned_methods
  @scanned_methods
end

#scoreObject

Returns the value of attribute score.



11
12
13
# File 'lib/flog_builder.rb', line 11

def score
  @score
end

Instance Method Details

#average_scoreObject



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_scoreObject



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

#pathObject



18
19
20
# File 'lib/flog_builder.rb', line 18

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

#to_htmlObject



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