Sha256: 41f3592e72c89ddef9745e7b50b2205595ea85622225bfc240ca3d4313376012

Contents?: true

Size: 1.13 KB

Versions: 96

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

# title: CSV Export
# description: Export CSV formatted data with header row
# author: Brett Terpstra
# url: https://brettterpstra.com
module Doing
  ##
  ## CSV Export
  ##
  class CSVExport
    include Doing::Util

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

    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

    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

    Doing::Plugins.register 'csv', :export, self
  end
end

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
doing-2.1.88 lib/doing/plugins/export/csv_export.rb
doing-2.1.87 lib/doing/plugins/export/csv_export.rb
doing-2.1.86 lib/doing/plugins/export/csv_export.rb
doing-2.1.85 lib/doing/plugins/export/csv_export.rb
doing-2.1.84 lib/doing/plugins/export/csv_export.rb
doing-2.1.83 lib/doing/plugins/export/csv_export.rb
doing-2.1.82 lib/doing/plugins/export/csv_export.rb
doing-2.1.81 lib/doing/plugins/export/csv_export.rb
doing-2.1.80 lib/doing/plugins/export/csv_export.rb
doing-2.1.79 lib/doing/plugins/export/csv_export.rb
doing-2.1.78 lib/doing/plugins/export/csv_export.rb
doing-2.1.77 lib/doing/plugins/export/csv_export.rb
doing-2.1.76 lib/doing/plugins/export/csv_export.rb
doing-2.1.75 lib/doing/plugins/export/csv_export.rb
doing-2.1.74 lib/doing/plugins/export/csv_export.rb
doing-2.1.73 lib/doing/plugins/export/csv_export.rb
doing-2.1.72 lib/doing/plugins/export/csv_export.rb
doing-2.1.69 lib/doing/plugins/export/csv_export.rb
doing-2.1.68 lib/doing/plugins/export/csv_export.rb
doing-2.1.66 lib/doing/plugins/export/csv_export.rb