Class: StatsFormatter
- Inherits:
-
Object
- Object
- StatsFormatter
- Defined in:
- lib/stats_formatter.rb
Overview
Classe de formatage des resultats renvoyes par rake stats Author: Vincent Dubois
Instance Attribute Summary collapse
-
#percent ⇒ Object
readonly
Returns the value of attribute percent.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(result) ⇒ StatsFormatter
constructor
Constructeur.
-
#to_html ⇒ Object
Methode qui permet de fabriquer le flux HTML a partir des flux console.
Constructor Details
#initialize(result) ⇒ StatsFormatter
Constructeur
10 11 12 |
# File 'lib/stats_formatter.rb', line 10 def initialize result self.result = result end |
Instance Attribute Details
#percent ⇒ Object (readonly)
Returns the value of attribute percent.
7 8 9 |
# File 'lib/stats_formatter.rb', line 7 def percent @percent end |
#result ⇒ Object
Returns the value of attribute result.
6 7 8 |
# File 'lib/stats_formatter.rb', line 6 def result @result end |
Instance Method Details
#to_html ⇒ Object
Methode qui permet de fabriquer le flux HTML a partir des flux console
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stats_formatter.rb', line 15 def to_html html = "<table class='bodyTable'><thead><th>Name</th><th>Lines</th><th>LOC</th><th>Classes</th><th>Methods</th><th>M/C</th><th>LOC/M</th></thead><tbody>" i = 0 results = self.result.split(/$/) bottom = 4 while !results[bottom].nil? and results[bottom][0..1] != "\n+" do bottom = bottom + 1 end lines = results[4..bottom-1] lines.each do |line| elements = line.split(/\|/) html = html + "<tr class='#{ i % 2 == 0 ? 'a' : 'b'}'>" html = html + "<td><strong>#{elements[1]}</strong></td>" html = html + "<td style='text-align: right;'>#{elements[2]}</td>" html = html + "<td style='text-align: right;'>#{elements[3]}</td>" html = html + "<td style='text-align: right;'>#{elements[4]}</td>" html = html + "<td style='text-align: right;'>#{elements[5]}</td>" html = html + "<td style='text-align: right;'>#{elements[6]}</td>" html = html + "<td style='text-align: right;'>#{elements[7]}</td>" html = html + "</tr>" i = i + 1 end total = results[bottom + 1] elements = total.split(/\|/) html = html + "<tr class='#{ i % 2 == 0 ? 'a' : 'b'}'>" html = html + "<td><strong>#{elements[1]}</strong></td>" [2,3,4,5,6,7].each do |j| html = html + "<td style='text-align: right;'><strong>#{elements[j]}</strong></td>" end html = html + "</tr>" html = html + "</tbody></table>" extra = results[bottom + 3] elements = extra.split(/:| /) @percent = (elements[3].strip.to_f * 100.0) / elements[1].strip.to_f html = html + "<p><strong>#{elements[0]} : </strong>#{elements[1]}      " html = html + "<strong>#{elements[2]} : </strong>#{elements[3]}      " html = html + "<strong>#{elements[4]} : </strong>#{elements[5]}:#{elements[6]}</p><br/>" end |