Class: CSVWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/output/csv/csv_writer.rb

Overview

Singleton class to write the provided output in a csv-formatted file

Class Method Summary collapse

Class Method Details

.output(filename, person, tasks, additions) ⇒ Object

public entry point to create the csv file

Parameters:

  • filename (String) —

    the path of the output file

  • person (Person) —

    the person whose tasks should be written

  • tasks (Array) —

    the result tasks

  • additions (Array) —

    additonal lines which should follow the tasks in the csv output



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/output/csv/csv_writer.rb', line 13

def self.output(filename, person, tasks, additions)
  output = Array.new()

  output << AttributeStringFactory.get_attributes_to_person(person)
  output << person.to_file

  output << String.new()

  output << AttributeStringFactory.get_attributes_to_task
  tasks.each { |task|
    output << task.to_file
  }

  output << String.new()
  additions.each { |entry|
    output << entry
  }
  write(filename, output)
end

.write(filename, output) ⇒ Object

method to print the output into the file

Parameters:

  • filename (String) —

    the path of the output file

  • output (Array) —

    the prepared output lines



37
38
39
40
41
42
43
# File 'lib/output/csv/csv_writer.rb', line 37

def self.write(filename, output)
  CSV.open(filename, "wb", {:col_sep => ";"}) { |csv|
    output.each { |entry|
      csv << entry.split(";")
    }
  }
end