Class: Delta::SetOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/delta/set_operator.rb,
lib/delta/set_operator/enumerable.rb,
lib/delta/set_operator/active_record.rb

Direct Known Subclasses

ActiveRecord, Enumerable

Defined Under Namespace

Classes: ActiveRecord, Enumerable

Constant Summary collapse

ADAPTERS =
[ActiveRecord, Enumerable]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a:, b:, identifiers:, changes:) ⇒ SetOperator

Returns a new instance of SetOperator.



17
18
19
20
21
22
# File 'lib/delta/set_operator.rb', line 17

def initialize(a:, b:, identifiers:, changes:)
  self.a = a
  self.b = b
  self.identifiers = identifiers
  self.changes = changes
end

Class Method Details

.adapt(a:, b:, identifiers:, changes:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/delta/set_operator.rb', line 5

def self.adapt(a:, b:, identifiers:, changes:)
  adapter = ADAPTERS.find { |klass| klass.compatible?(a, b) }
  adapter = ADAPTERS.last unless adapter

  adapter.new(
    a: a,
    b: b,
    identifiers: identifiers,
    changes: changes
  )
end

Instance Method Details

#a_minus_bObject



24
25
26
# File 'lib/delta/set_operator.rb', line 24

def a_minus_b
  subtract(a, b)
end

#b_minus_aObject



28
29
30
# File 'lib/delta/set_operator.rb', line 28

def b_minus_a
  subtract(b, a)
end

#intersectionObject



32
33
34
# File 'lib/delta/set_operator.rb', line 32

def intersection
  intersect(a, b)
end