Module: CSVPlusPlus::Writer::Merger

Extended by:
T::Sig
Includes:
Kernel
Included in:
CSV, GoogleSheetsBuilder, RubyXLBuilder
Defined in:
lib/csv_plus_plus/writer/merger.rb

Overview

A merging strategy for when we want to write to a cell but it has a value

Instance Method Summary collapse

Instance Method Details

#merge_cell_value(existing_value:, new_value:, options:) ⇒ Object

Consistently enforce our strategy for resolving differences between new changes and existing. By default we overwrite values that are currently in the spreadsheet but you can override that with the –safe flag



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/csv_plus_plus/writer/merger.rb', line 21

def merge_cell_value(existing_value:, new_value:, options:)
  merged_value = merge_with_strategy(existing_value:, new_value:, options:)

  return merged_value unless options.verbose

  if options.overwrite_values && merged_value != existing_value
    warn("Overwriting existing value: \"#{existing_value}\" with \"#{new_value}\"")
  # rubocop:disable Style/MissingElse
  elsif !options.overwrite_values && new_value != merged_value
    # rubocop:enable Style/MissingElse
    warn("Keeping old value: \"#{existing_value}\" rather than new value: \"#{new_value}\"")
  end

  merged_value
end