Module: Kennel::Syncer::MatchedExpected

Defined in:
lib/kennel/syncer/matched_expected.rb

Class Method Summary collapse

Class Method Details

.partition(expected, actual) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kennel/syncer/matched_expected.rb', line 7

def partition(expected, actual)
  lookup_map = matching_expected_lookup_map(expected)
  unmatched_expected = Set.new(expected) # for efficient deletion
  unmatched_actual = []
  matched = []
  actual.each do |a|
    e = matching_expected(a, lookup_map)
    if e && unmatched_expected.delete?(e)
      matched << [e, a]
    else
      unmatched_actual << a
    end
  end.compact
  [matched, unmatched_expected.to_a, unmatched_actual]
end