Class: Eco::Data::Hashes::ArrayDiff
- Extended by:
- Language::Klass::HelpersBuilt
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/data/hashes/array_diff.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#source_1 ⇒ Object
readonly
Returns the value of attribute source_1.
-
#source_2 ⇒ Object
readonly
Returns the value of attribute source_2.
-
#src_h_1 ⇒ Object
readonly
Returns the value of attribute src_h_1.
-
#src_h_2 ⇒ Object
readonly
Returns the value of attribute src_h_2.
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#diffs ⇒ Hash
Where
keyis the key of the record, andvalueaDiffResultobject. -
#diffs? ⇒ Boolean
Wheter or not there are differences.
-
#initialize(source_1, source_2, 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::Klass::InheritableClassVars
#inheritable_attrs, #inheritable_class_vars, #inherited
Methods included from Language::Klass::Naming
#instance_variable_name, #to_constant
Methods included from Language::Klass::Hierarchy
Methods included from Language::Klass::Builder
Methods included from Language::Klass::Uid
Methods included from Language::Klass::Resolver
#class_resolver, #resolve_class
Methods included from Language::Klass::Const
#if_const, #redef_without_warning
Methods included from Language::AuxiliarLogger
Constructor Details
#initialize(source_1, source_2, logger: nil) ⇒ ArrayDiff
Returns a new instance of ArrayDiff.
15 16 17 18 19 20 21 22 |
# File 'lib/eco/data/hashes/array_diff.rb', line 15 def initialize(source_1, source_2, logger: nil) @logger = logger if logger @source_1 = source_1 @source_2 = source_2 raise "Missing source_1" unless (@src_h_1 = by_key(source_1)) raise "Missing source_2" unless (@src_h_2 = by_key(source_2)) end |
Instance Attribute Details
#source_1 ⇒ Object (readonly)
Returns the value of attribute source_1.
12 13 14 |
# File 'lib/eco/data/hashes/array_diff.rb', line 12 def source_1 @source_1 end |
#source_2 ⇒ Object (readonly)
Returns the value of attribute source_2.
12 13 14 |
# File 'lib/eco/data/hashes/array_diff.rb', line 12 def source_2 @source_2 end |
#src_h_1 ⇒ Object (readonly)
Returns the value of attribute src_h_1.
13 14 15 |
# File 'lib/eco/data/hashes/array_diff.rb', line 13 def src_h_1 @src_h_1 end |
#src_h_2 ⇒ Object (readonly)
Returns the value of attribute src_h_2.
13 14 15 |
# File 'lib/eco/data/hashes/array_diff.rb', line 13 def src_h_2 @src_h_2 end |
Instance Method Details
#diffs ⇒ Hash
- A
Hash::DiffResultobject, offershash_diffwith 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 |
# File 'lib/eco/data/hashes/array_diff.rb', line 28 def diffs @diffs ||= source_results.select(&:diff?) end |
#diffs? ⇒ Boolean
Returns wheter or not there are differences.
33 34 35 |
# File 'lib/eco/data/hashes/array_diff.rb', line 33 def diffs? diffs.any? end |
#source_results ⇒ Array<Eco::Data::Hash::DiffResult>
All the items that contain the diff of a node.
39 40 41 42 43 44 |
# File 'lib/eco/data/hashes/array_diff.rb', line 39 def source_results @source_results ||= paired_sources.each_with_object([]) do |(src_1, src_2), res| res << diff_result_class.new(src_1, src_2) end end |