Class: NcsNavigator::Mdes::Differences::Entry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ncs_navigator/mdes/differences/entry.rb

Overview

Captures the differences between two instances of one of the elements that makes up a specification. I.e., TransmissionTable, Variable, VariableType, or CodeListEntry.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#attribute_differencesHash<Symbol, Object>

Return the differences for each attribute. Each key is the name of the attribute and each value is an object describing the difference. It might be a Value diff, a Collection diff, or another NcsNavigator::Mdes::Differences::Entry diff depending on the kind of attribute.

Returns:

  • (Hash<Symbol, Object>)


42
43
44
# File 'lib/ncs_navigator/mdes/differences/entry.rb', line 42

def attribute_differences
  @attribute_differences ||= {}
end

Class Method Details

.compute(o1, o2, attribute_criteria, diff_options) ⇒ Entry?

Returns the differences between o1 and o2 according to the criteria, or nil if there are no differences.

Parameters:

  • o1 (Object)

    the left object

  • o2 (Object)

    the right object

  • attribute_criteria (Hash<Symbol, #apply>)

    a list of objects which produce difference objects

  • diff_options (Hash)

    options to pass to nested calls to #diff

Returns:

  • (Entry, nil)

    the differences between o1 and o2 according to the criteria, or nil if there are no differences.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ncs_navigator/mdes/differences/entry.rb', line 17

def self.compute(o1, o2, attribute_criteria, diff_options)
  differences = attribute_criteria.each_with_object({}) do |(diff_attribute, criterion), diffs|
    o_attribute = (criterion.respond_to?(:attribute) && criterion.attribute) || diff_attribute
    d = criterion.apply(o1.send(o_attribute), o2.send(o_attribute), diff_options)
    diffs[diff_attribute] = d if d
  end

  if differences.empty?
    nil
  else
    Entry.new.tap { |e| e.attribute_differences = differences }
  end
end