Class: Doing::CSVExport

Inherits:
Object show all
Includes:
Util
Defined in:
lib/doing/plugins/export/csv_export.rb

Overview

CSV Export

Class Method Summary collapse

Methods included from Util

#args_for_editor, #deep_merge_hashes, #deep_merge_hashes!, #default_editor, #duplicable?, #duplicate_frozen_values, #editor_with_args, #exec_available, #find_default_editor, #first_available_exec, #mergable?, #merge_default_proc, #merge_values, #safe_load_file, #user_home, #write_to_file

Class Method Details

.format_note(note) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/doing/plugins/export/csv_export.rb', line 36

def self.format_note(note)
  out = ''
  if note
    arr = note.map(&:strip).delete_if { |e| e =~ /^\s*$/ }
    out = arr.join("\n") unless arr.empty?
  end

  out
end

.render(wwid, items, variables: {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/doing/plugins/export/csv_export.rb', line 20

def self.render(wwid, items, variables: {})
  return if items.nil?

  opt = variables[:options]

  output = [CSV.generate_line(%w[start end title note timer section])]
  items.each do |i|
    note = format_note(i.note)
    end_date = i.end_date
    interval = end_date && opt[:times] ? wwid.get_interval(i, formatted: false) : 0
    output.push(CSV.generate_line([i.date, end_date, i.title, note, interval, i.section]))
  end
  Doing.logger.debug('CSV Export:', "#{items.count} items output to CSV")
  output.join('')
end

.settingsObject



14
15
16
17
18
# File 'lib/doing/plugins/export/csv_export.rb', line 14

def self.settings
  {
    trigger: 'csv'
  }
end