Class: Notes::CsvExport

Inherits:
BaseExport show all
Defined in:
lib/notes/export/csv_export.rb

Constant Summary collapse

CSV_VALUE_SEPARATOR =
', '

Constants inherited from BaseExport

BaseExport::DESCRIPTION, BaseExport::DUE_DATE, BaseExport::TAG, BaseExport::TOKEN

Instance Method Summary collapse

Constructor Details

#initialize(output_file_path) ⇒ CsvExport

Returns a new instance of CsvExport.



5
6
7
# File 'lib/notes/export/csv_export.rb', line 5

def initialize output_file_path
  @file = File.new output_file_path, 'w+'
end

Instance Method Details

#export_note(note_hash) ⇒ Object



20
21
22
23
24
25
# File 'lib/notes/export/csv_export.rb', line 20

def export_note note_hash
  res = note_hash[Options::TOKEN.to_s]  + CSV_VALUE_SEPARATOR + get_tags_string(note_hash[Options::TAG.to_s])
  res +=  CSV_VALUE_SEPARATOR + '"' + note_hash[Options::DESCRIPTION.to_s] + '"'
  res += CSV_VALUE_SEPARATOR + note_hash[Options::DUE_DATE.to_s]
  res
end

#export_notes(notes_list) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/notes/export/csv_export.rb', line 9

def export_notes notes_list
  res = TOKEN + CSV_VALUE_SEPARATOR + TAG + CSV_VALUE_SEPARATOR + DESCRIPTION + CSV_VALUE_SEPARATOR + DUE_DATE + "\n"
  notes_list.each do |note|
    res += export_note note
    res += "\n"
  end
  res.chomp! "\n"
  @file.puts res
  @file.close
end