Class: CountLOC::CsvFileWriter
- Inherits:
-
Object
- Object
- CountLOC::CsvFileWriter
- Defined in:
- lib/countloc.rb
Overview
Class that writes to a csv file
Instance Method Summary collapse
-
#initialize(filename) ⇒ CsvFileWriter
constructor
A new instance of CsvFileWriter.
-
#write(data) ⇒ Object
Write the csv file, including the data contents (via the to_csv method on the data).
Constructor Details
#initialize(filename) ⇒ CsvFileWriter
Returns a new instance of CsvFileWriter.
295 296 297 |
# File 'lib/countloc.rb', line 295 def initialize(filename) @filename = filename end |
Instance Method Details
#write(data) ⇒ Object
Write the csv file, including the data contents (via the to_csv method on the data)
301 302 303 304 305 306 307 |
# File 'lib/countloc.rb', line 301 def write(data) begin File.open(@filename, "wb") { |file| file.puts data.to_csv } rescue puts "Error: " + $!.to_s end end |