Class: Solid::Result::EventLogs::Tree::Node
- Inherits:
-
Object
- Object
- Solid::Result::EventLogs::Tree::Node
- Defined in:
- lib/solid/result/event_logs/tree.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#normalizer ⇒ Object
readonly
Returns the value of attribute normalizer.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, parent:, id:, normalizer:) ⇒ Node
constructor
A new instance of Node.
- #insert(value, id:) ⇒ Object
- #inspect ⇒ Object
- #leaf? ⇒ Boolean
- #node? ⇒ Boolean
- #root? ⇒ Boolean
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/solid/result/event_logs/tree.rb', line 7 def children @children end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/solid/result/event_logs/tree.rb', line 7 def id @id end |
#normalizer ⇒ Object (readonly)
Returns the value of attribute normalizer.
7 8 9 |
# File 'lib/solid/result/event_logs/tree.rb', line 7 def normalizer @normalizer end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/solid/result/event_logs/tree.rb', line 7 def parent @parent end |
#value ⇒ Object (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 |
#inspect ⇒ Object
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
31 32 33 |
# File 'lib/solid/result/event_logs/tree.rb', line 31 def leaf? children.empty? end |
#node? ⇒ Boolean
35 36 37 |
# File 'lib/solid/result/event_logs/tree.rb', line 35 def node? !leaf? end |
#root? ⇒ Boolean
27 28 29 |
# File 'lib/solid/result/event_logs/tree.rb', line 27 def root? parent.nil? end |