Class: Library::Node
- Inherits:
-
Object
- Object
- Library::Node
- Defined in:
- lib/danta/library/node.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(name:, parent: nil, nodes: []) ⇒ Node
constructor
A new instance of Node.
- #leaf? ⇒ Boolean
- #root? ⇒ Boolean
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(name:, parent: nil, nodes: []) ⇒ Node
Returns a new instance of Node.
12 13 14 15 16 |
# File 'lib/danta/library/node.rb', line 12 def initialize(name:, parent: nil, nodes: []) @name = name @nodes = nodes @parent = parent end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/danta/library/node.rb', line 7 def name @name end |
#nodes ⇒ Object
Returns the value of attribute nodes.
8 9 10 |
# File 'lib/danta/library/node.rb', line 8 def nodes @nodes end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/danta/library/node.rb', line 10 def parent @parent end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/danta/library/node.rb', line 9 def path @path end |
Instance Method Details
#leaf? ⇒ Boolean
22 23 24 |
# File 'lib/danta/library/node.rb', line 22 def leaf? nodes.empty? end |
#root? ⇒ Boolean
18 19 20 |
# File 'lib/danta/library/node.rb', line 18 def root? parent.empty? end |
#to_h ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/danta/library/node.rb', line 26 def to_h { name: name, path: path, nodes: nodes.map(&:to_h) } end |
#to_json ⇒ Object
34 35 36 |
# File 'lib/danta/library/node.rb', line 34 def to_json to_h.to_json end |