Class: Metricks::FlogReporter::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/metricks/flog_reporter/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Page.



5
6
7
8
# File 'lib/metricks/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/metricks/flog_reporter/page.rb', line 3

def scanned_methods
  @scanned_methods
end

#scoreObject

Returns the value of attribute score.



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

def score
  @score
end

Instance Method Details

#average_scoreObject



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

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

#highest_scoreObject



30
31
32
33
34
# File 'lib/metricks/flog_reporter/page.rb', line 30

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

#to_htmlObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/metricks/flog_reporter/page.rb', line 10

def to_html
  output = "<html><head><style>"
  output << Base.load_css
  output << "</style></head><body>"
  output << "Score: #{score}\n"
  scanned_methods.each do |sm|
    output << sm.to_html
  end
  output << "</body></html>"
  output
end