Class: CountLOC::Results

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

Overview

Container class to store results from each file.

Instance Method Summary collapse

Instance Method Details

#to_csvObject

Return a string containing all the results in csv format. The first row is a header row of the column names. Each subsequent row corresponds to a result from the results array.



253
254
255
256
257
# File 'lib/countloc.rb', line 253

def to_csv
  csvString = LineCounter.columnNames.join(',') + "\n"
  self.each { |result| csvString += result.to_a.join(',')  + "\n"}
  csvString
end

#to_htmlObject

Return a string containing the results formatted as a html table. The first row is a header row of the column names. Each subsequent row corresponds to a result from the results array.



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/countloc.rb', line 262

def to_html
  htmlString = %{<table border="1" cellspacing="0" cellpadding="2">}
  htmlString += %{<tr>}
  LineCounter.columnNames.each { |name| htmlString += %{<th>#{name}</th>} }
  htmlString += %{</tr>}
  self.each do |result|
    htmlString += %{<tr>}
    result.to_a.each { |cell| htmlString += %{<td>#{cell}</td> } }
    htmlString += %{</tr>}
  end
  htmlString += %{</table>}
  htmlString += %{<p><em>Generated by } +
  %{<a href="http://countloc.rubyforge.org">countloc</a> version #{VERSION} } +
  %{on #{Time.now.asctime}</em></p>}
end

#to_sObject

Return a string containing all the results.



244
245
246
247
248
# File 'lib/countloc.rb', line 244

def to_s
  str = LineCounter.headline + "\n"
  self.each { |result| str += result.to_s + "\n"}
  str
end