Class: Eco::Data::Hashes::ArrayDiff

Inherits:
Object
  • Object
show all
Extended by:
Language::Models::ClassHelpers
Includes:
Language::AuxiliarLogger
Defined in:
lib/eco/data/hashes/array_diff.rb

Direct Known Subclasses

Locations::NodeDiff::NodesDiff

Constant Summary

Constants included from Language::Models::ClassHelpers

Language::Models::ClassHelpers::NOT_USED

Instance Attribute Summary collapse

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

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

#log

Constructor Details

#initialize(source_1, source_2, logger: nil) ⇒ ArrayDiff

Returns a new instance of ArrayDiff.



14
15
16
17
18
19
20
21
# File 'lib/eco/data/hashes/array_diff.rb', line 14

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_1Object (readonly)

Returns the value of attribute source_1.



11
12
13
# File 'lib/eco/data/hashes/array_diff.rb', line 11

def source_1
  @source_1
end

#source_2Object (readonly)

Returns the value of attribute source_2.



11
12
13
# File 'lib/eco/data/hashes/array_diff.rb', line 11

def source_2
  @source_2
end

#src_h_1Object (readonly)

Returns the value of attribute src_h_1.



12
13
14
# File 'lib/eco/data/hashes/array_diff.rb', line 12

def src_h_1
  @src_h_1
end

#src_h_2Object (readonly)

Returns the value of attribute src_h_2.



12
13
14
# File 'lib/eco/data/hashes/array_diff.rb', line 12

def src_h_2
  @src_h_2
end

Instance Method Details

#diffsHash

Note:
  • A Hash::DiffResult object, offers hash_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.

Returns:

  • (Hash)

    where key is the key of the record, and value a DiffResult object



27
28
29
# File 'lib/eco/data/hashes/array_diff.rb', line 27

def diffs
  @diffs ||= source_results.select(&:diff?)
end

#diffs?Boolean

Returns wheter or not there are differences.

Returns:

  • (Boolean)

    wheter or not there are differences.



32
33
34
# File 'lib/eco/data/hashes/array_diff.rb', line 32

def diffs?
  diffs.any?
end

#source_resultsArray<Eco::Data::Hash::DiffResult>

All the items that contain the diff of a node.

Returns:

  • (Array<Eco::Data::Hash::DiffResult>)


38
39
40
41
42
# File 'lib/eco/data/hashes/array_diff.rb', line 38

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