Class: Eco::Data::Hashes::ArrayDiff
- Inherits:
-
Object
- Object
- Eco::Data::Hashes::ArrayDiff
- Extended by:
- Language::Models::ClassHelpers
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/data/hashes/array_diff.rb
Direct Known Subclasses
Constant Summary
Constants included from Language::Models::ClassHelpers
Language::Models::ClassHelpers::NOT_USED
Instance Attribute Summary collapse
-
#source1 ⇒ Object
readonly
Returns the value of attribute source1.
-
#source2 ⇒ Object
readonly
Returns the value of attribute source2.
-
#src_h1 ⇒ Object
readonly
Returns the value of attribute src_h1.
-
#src_h2 ⇒ Object
readonly
Returns the value of attribute src_h2.
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#diffs ⇒ Hash
Where
key
is the key of the record, andvalue
aDiffResult
object. -
#diffs? ⇒ Boolean
Wheter or not there are differences.
-
#initialize(source1, source2, logger: nil) ⇒ ArrayDiff
constructor
A new instance of ArrayDiff.
-
#source_results ⇒ Array<Eco::Data::Hash::DiffResult>
All the items that contain the diff of a node.
Methods included from Language::Models::ClassHelpers
class_resolver, inheritable_attrs, inheritable_class_vars, inherited, instance_variable_name, new_class, redef_without_warning, resolve_class, to_constant, used_param?
Methods included from Language::AuxiliarLogger
Constructor Details
#initialize(source1, source2, logger: nil) ⇒ ArrayDiff
Returns a new instance of ArrayDiff.
14 15 16 17 18 19 20 21 22 |
# File 'lib/eco/data/hashes/array_diff.rb', line 14 def initialize(source1, source2, logger: nil) @logger = logger if logger @source1 = source1 @source2 = source2 @src_h1 = by_key(source1) @src_h2 = by_key(source2) raise "Missing source1" unless !!self.src_h1 raise "Missing source2" unless !!self.src_h2 end |
Instance Attribute Details
#source1 ⇒ Object (readonly)
Returns the value of attribute source1.
11 12 13 |
# File 'lib/eco/data/hashes/array_diff.rb', line 11 def source1 @source1 end |
#source2 ⇒ Object (readonly)
Returns the value of attribute source2.
11 12 13 |
# File 'lib/eco/data/hashes/array_diff.rb', line 11 def source2 @source2 end |
#src_h1 ⇒ Object (readonly)
Returns the value of attribute src_h1.
12 13 14 |
# File 'lib/eco/data/hashes/array_diff.rb', line 12 def src_h1 @src_h1 end |
#src_h2 ⇒ Object (readonly)
Returns the value of attribute src_h2.
12 13 14 |
# File 'lib/eco/data/hashes/array_diff.rb', line 12 def src_h2 @src_h2 end |
Instance Method Details
#diffs ⇒ Hash
- A
Hash::DiffResult
object, offershash_diff
with the attrs that have changed value - It also allows to know the original value
Returns where key
is the key of the record, and value
a DiffResult
object.
28 29 30 31 32 |
# File 'lib/eco/data/hashes/array_diff.rb', line 28 def diffs @diffs ||= source_results.select do |res| res.diff? end end |
#diffs? ⇒ Boolean
Returns wheter or not there are differences.
35 36 37 |
# File 'lib/eco/data/hashes/array_diff.rb', line 35 def diffs? !diffs.empty? end |
#source_results ⇒ Array<Eco::Data::Hash::DiffResult>
All the items that contain the diff of a node.
41 42 43 44 45 |
# File 'lib/eco/data/hashes/array_diff.rb', line 41 def source_results @source_results ||= paired_sources.each_with_object([]) do |(src1, src2), res| res << diff_result_class.new(src1, src2) end end |