Class: FlatKit::Merge
- Inherits:
-
Object
- Object
- FlatKit::Merge
- Includes:
- EventEmitter
- Defined in:
- lib/flat_kit/merge.rb
Overview
Internal: Class implementing merging from N inputs and output to 1 output.
Instance Attribute Summary collapse
-
#compare_fields ⇒ Object
readonly
Returns the value of attribute compare_fields.
-
#readers ⇒ Object
readonly
Returns the value of attribute readers.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(inputs:, output:, compare_fields:, input_fallback: "auto", output_fallback: "auto") ⇒ Merge
constructor
A new instance of Merge.
Methods included from EventEmitter
#_listeners, #add_listener, #count_listeners, #notify_listeners, #remove_listener, #remove_listeners
Constructor Details
#initialize(inputs:, output:, compare_fields:, input_fallback: "auto", output_fallback: "auto") ⇒ Merge
Returns a new instance of Merge.
11 12 13 14 15 16 17 |
# File 'lib/flat_kit/merge.rb', line 11 def initialize(inputs:, output:, compare_fields:, input_fallback: "auto", output_fallback: "auto") @compare_fields = compare_fields @readers = ::FlatKit::Reader.create_readers_from_paths(paths: inputs, compare_fields: @compare_fields, fallback: input_fallback) @writer = ::FlatKit::Writer.create_writer_from_path(path: output, fallback: output_fallback, reader_format: @readers.first.format_name) end |
Instance Attribute Details
#compare_fields ⇒ Object (readonly)
Returns the value of attribute compare_fields.
9 10 11 |
# File 'lib/flat_kit/merge.rb', line 9 def compare_fields @compare_fields end |
#readers ⇒ Object (readonly)
Returns the value of attribute readers.
9 10 11 |
# File 'lib/flat_kit/merge.rb', line 9 def readers @readers end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
9 10 11 |
# File 'lib/flat_kit/merge.rb', line 9 def writer @writer end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/flat_kit/merge.rb', line 19 def call ::FlatKit.logger.debug "Merging the following files into #{writer.destination}" ::FlatKit.logger.debug "Using this key for sorting: #{compare_fields.join(', ')}" readers.each do |r| ::FlatKit.logger.debug " #{r.source}" end run_merge(readers) readers.each do |r| ::FlatKit.logger.debug " #{r.source} produced #{r.count} records" end writer.close ::FlatKit.logger.debug "Wrote #{writer.count} records to #{writer.destination}" end |