Class: TreeDelta::Intermediate

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_delta/intermediate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from:, to:) ⇒ Intermediate

Returns a new instance of Intermediate.



5
6
7
# File 'lib/tree_delta/intermediate.rb', line 5

def initialize(from:, to:)
  @from, @to = from, to
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/tree_delta/intermediate.rb', line 3

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



3
4
5
# File 'lib/tree_delta/intermediate.rb', line 3

def to
  @to
end

Instance Method Details

#attachesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tree_delta/intermediate.rb', line 59

def attaches
  Enumerator.new do |y|
    moves.each do |node|
      unless root?(node)
        y.yield TreeDelta::Operation.new(
          type:     :attach,
          identity: node.identity,
          parent:   parent_identity(node),
          position: position(node)
        )
      end
    end
  end
end

#createsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tree_delta/intermediate.rb', line 9

def creates
  Enumerator.new do |y|
    additions.each do |node|
      y.yield TreeDelta::Operation.new(
        type:     :create,
        identity: node.identity,
        value:    node.value,
        parent:   parent_identity(node),
        position: position(node)
      )
    end
  end
end

#deletesObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/tree_delta/intermediate.rb', line 35

def deletes
  Enumerator.new do |y|
    normalised_deletions.each do |node|
      y.yield TreeDelta::Operation.new(
        type:     :delete,
        identity: node.identity
      )
    end
  end
end

#detachesObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tree_delta/intermediate.rb', line 46

def detaches
  Enumerator.new do |y|
    moves.each do |node|
      unless previous_root?(node)
        y.yield TreeDelta::Operation.new(
          type:     :detach,
          identity: node.identity
        )
      end
    end
  end
end

#updatesObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tree_delta/intermediate.rb', line 23

def updates
  Enumerator.new do |y|
    updated_nodes.each do |node|
      y.yield TreeDelta::Operation.new(
        type:     :update,
        identity: node.identity,
        value:    node.value,
      )
    end
  end
end