Sha256: de1f79ac2b56662766d8b8a7c4c4517623446c1ac733e9cdde9c92daf239159c

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

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 }.freeze

    # @!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(&:rowcount).min
    end

    def close
      @outputs.each(&:close)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
docparser-0.3.0 lib/docparser/output/multi_output.rb