Class: Solid::Result::EventLogs::Tree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/solid/result/event_logs/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, parent:, id:, normalizer:) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
15
16
17
# File 'lib/solid/result/event_logs/tree.rb', line 9

def initialize(value, parent:, id:, normalizer:)
  @normalizer = normalizer

  @id = id
  @value = normalizer.call(id, value)
  @parent = parent

  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



7
8
9
# File 'lib/solid/result/event_logs/tree.rb', line 7

def children
  @children
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/solid/result/event_logs/tree.rb', line 7

def id
  @id
end

#normalizerObject (readonly)

Returns the value of attribute normalizer.



7
8
9
# File 'lib/solid/result/event_logs/tree.rb', line 7

def normalizer
  @normalizer
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/solid/result/event_logs/tree.rb', line 7

def parent
  @parent
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/solid/result/event_logs/tree.rb', line 7

def value
  @value
end

Instance Method Details

#insert(value, id:) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/solid/result/event_logs/tree.rb', line 19

def insert(value, id:)
  node = self.class.new(value, parent: self, id: id, normalizer: normalizer)

  @children << node

  node
end

#inspectObject



39
40
41
# File 'lib/solid/result/event_logs/tree.rb', line 39

def inspect
  "#<#{self.class.name} id=#{id} children.size=#{children.size}>"
end

#leaf?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/solid/result/event_logs/tree.rb', line 31

def leaf?
  children.empty?
end

#node?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/solid/result/event_logs/tree.rb', line 35

def node?
  !leaf?
end

#root?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/solid/result/event_logs/tree.rb', line 27

def root?
  parent.nil?
end