class TTY::Tree::Node
A representation of tree node
@api private
Constants
- ROOT
Attributes
level[R]
The directory depth
name[R]
The base name for the directory or file
parent[R]
The parent directory path
path[R]
The current path
prefix[R]
The require path prefix
stat[R]
The file stat
Public Class Methods
new(path, parent, prefix, level)
click to toggle source
# File lib/tty/tree/node.rb, line 35 def initialize(path, parent, prefix, level) if path.is_a? String # strip null bytes from the string to avoid throwing errors path = path.delete("\0") end @path = Pathname.new(path) @name = @path.basename @parent = Pathname.new(parent) @prefix = prefix @level = level end
Public Instance Methods
==(other)
click to toggle source
# File lib/tty/tree/node.rb, line 70 def ==(other) other.is_a?(self.class) && other.state_attrs == state_attrs end
Also aliased as: eql?
full_path()
click to toggle source
# File lib/tty/tree/node.rb, line 48 def full_path return parent if name.to_s.empty? parent.join(name) end
leaf?()
click to toggle source
# File lib/tty/tree/node.rb, line 62 def leaf? false end
root?()
click to toggle source
# File lib/tty/tree/node.rb, line 54 def root? parent.to_s.empty? end
to_s()
click to toggle source
# File lib/tty/tree/node.rb, line 66 def to_s @name end
Protected Instance Methods
state_attrs()
click to toggle source
# File lib/tty/tree/node.rb, line 77 def state_attrs [@name, @path, @parent, @prefix, @level] end