Class: Spoom::FileTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/file_tree.rb

Overview

A node representing either a file or a directory inside a FileTree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, parent: nil, children: {}) ⇒ Node

: (name: String, ?parent: Node?, ?children: Hash[String, Node]) -> void



92
93
94
95
96
# File 'lib/spoom/file_tree.rb', line 92

def initialize(name:, parent: nil, children: {})
  @parent = parent
  @name = name
  @children = children
end

Instance Attribute Details

#children ⇒ Object (readonly)

: Hash[String, Node]



89
90
91
# File 'lib/spoom/file_tree.rb', line 89

def children
  @children
end

#name ⇒ Object (readonly)

: String



84
85
86
# File 'lib/spoom/file_tree.rb', line 84

def name
  @name
end

#parent ⇒ Object (readonly)

Node parent or nil if the node is a root one : Node?



79
80
81
# File 'lib/spoom/file_tree.rb', line 79

def parent
  @parent
end

Instance Method Details

#path ⇒ Object

Full path to this node from root : -> String



100
101
102
103
104
105
# File 'lib/spoom/file_tree.rb', line 100

def path
  parent = self.parent
  return name unless parent

  "#{parent.path}/#{name}"
end