Class: CountLOC::CsvFileWriter

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

Overview

Class that writes to a csv file

Instance Method Summary collapse

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