Sha256: 0c592797e2bda6eabc6430ae002fe13ca9a8222b3650dc29b420d3987116ac38

Contents?: true

Size: 988 Bytes

Versions: 3

Compression:

Stored size: 988 Bytes

Contents

module DocParser
  # The MultiOutput output combines multiple outputs.
  # It creates a CSV, HTML, YAML and XLSX Output file
  # @see CSVOutput
  # @see HTMLOutput
  # @see YAMLOutput
  # @see XLSXOutput
  # @see Output
  class MultiOutput < Output
    # All the possible outputs
    OUTPUT_TYPES = { csv: CSVOutput, html: HTMLOutput, yml: YAMLOutput,
                     xlsx: XLSXOutput, json: JSONOutput }

    # @!visibility private
    def initialize(**options)
      @outputs = []
      OUTPUT_TYPES.each do |type, output|
        output_options = options.clone
        output_options[:filename] += '.' + type.to_s
        @outputs << output.new(output_options)
      end
    end

    def header=(row)
      @outputs.each { |out|  out.header = row }
    end

    def add_row(row)
      @outputs.each { |out|  out.add_row row }
    end

    def rowcount
      @outputs.map { |out| out.rowcount }.min
    end

    def close
      @outputs.each { |out|  out.close }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
docparser-0.2.2 lib/docparser/output/multi_output.rb
docparser-0.2.0 lib/docparser/output/multi_output.rb
docparser-0.1.6 lib/docparser/output/multi_output.rb