lib/docparser/output/multi_output.rb in docparser-0.1.4 vs lib/docparser/output/multi_output.rb in docparser-0.1.6
- old
+ new
@@ -5,28 +5,22 @@
# @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 = []
- csvoptions = options.clone
- csvoptions[:filename] += '.csv'
- htmloptions = options.clone
- htmloptions[:filename] += '.html'
- yamloptions = options.clone
- yamloptions[:filename] += '.yml'
- xlsxoptions = options.clone
- xlsxoptions[:filename] += '.xlsx'
- jsonoptions = options.clone
- jsonoptions[:filename] += '.json'
- @outputs << CSVOutput.new(csvoptions)
- @outputs << HTMLOutput.new(htmloptions)
- @outputs << YAMLOutput.new(yamloptions)
- @outputs << XLSXOutput.new(xlsxoptions)
- @outputs << JSONOutput.new(jsonoptions)
+ 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
@@ -41,6 +35,6 @@
def close
@outputs.each { |out| out.close }
end
end
-end
\ No newline at end of file
+end