Method: CSVDiff::Source#initialize
- Defined in:
- lib/csv-diff/source.rb
#initialize(options = {}) ⇒ Source
Creates a new diff source.
A diff source must contain at least one field that will be used as the key to identify the same record in a different version of this file. If not specified via one of the options, the first field is assumed to be the unique key.
If multiple fields combine to form a unique key, the combined fields are considered as a single unique identifier. If your key represents data that can be represented as a tree, you can instead break your key fields into :parent_fields and :child_fields. By doing this, if a child key is deleted from one parent, and added to another, that will be reported as an update, with a change to the parent key part(s) of the record.
All key options can be specified either by field name, or by field index (0 based).
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/csv-diff/source.rb', line 102 def initialize( = {}) if (.keys & [:parent_field, :parent_fields, :child_field, :child_fields]).empty? && (kf = .fetch(:key_field, [:key_fields])) @key_fields = [kf].flatten @parent_fields = [] @child_fields = @key_fields else @parent_fields = [.fetch(:parent_field, [:parent_fields]) || []].flatten @child_fields = [.fetch(:child_field, [:child_fields]) || [0]].flatten @key_fields = @parent_fields + @child_fields end @field_names = [:field_names] @case_sensitive = .fetch(:case_sensitive, true) @trim_whitespace = .fetch(:trim_whitespace, false) @ignore_header = [:ignore_header] @include = [:include] @exclued = [:exclude] @path = .fetch(:path, 'NA') unless @path @warnings = [] end |