Class: TTY::Tree::Node Private
- Inherits:
-
Object
- Object
- TTY::Tree::Node
- Extended by:
- Forwardable
- Defined in:
- lib/tty/tree/node.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A representation of tree node
Direct Known Subclasses
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
private
The directory depth.
-
#name ⇒ Object
readonly
private
The base name for the directory or file.
-
#parent ⇒ Object
readonly
private
The parent directory path.
-
#path ⇒ Object
readonly
private
The current path.
-
#prefix ⇒ Object
readonly
private
The require path prefix.
-
#stat ⇒ Object
readonly
private
The file stat.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?) private
- #full_path ⇒ Object private
- #hidden? ⇒ Boolean private
-
#initialize(path, parent, prefix, level) ⇒ Node
constructor
private
A new instance of Node.
- #leaf? ⇒ Boolean private
- #root? ⇒ Boolean private
- #to_s ⇒ Object private
Constructor Details
#initialize(path, parent, prefix, level) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Node.
35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#level ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The directory depth
24 25 26 |
# File 'lib/tty/tree/node.rb', line 24 def level @level end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The base name for the directory or file
15 16 17 |
# File 'lib/tty/tree/node.rb', line 15 def name @name end |
#parent ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The parent directory path
18 19 20 |
# File 'lib/tty/tree/node.rb', line 18 def parent @parent end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The current path
30 31 32 |
# File 'lib/tty/tree/node.rb', line 30 def path @path end |
#prefix ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The require path prefix
21 22 23 |
# File 'lib/tty/tree/node.rb', line 21 def prefix @prefix end |
#stat ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The file stat
27 28 29 |
# File 'lib/tty/tree/node.rb', line 27 def stat @stat end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/tty/tree/node.rb', line 70 def ==(other) other.is_a?(self.class) && other.state_attrs == state_attrs end |
#full_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 |
# File 'lib/tty/tree/node.rb', line 48 def full_path return parent if name.to_s.empty? parent.join(name) end |
#hidden? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 |
# File 'lib/tty/tree/node.rb', line 58 def hidden? name.to_s.start_with?('.') end |
#leaf? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/tty/tree/node.rb', line 62 def leaf? false end |
#root? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/tty/tree/node.rb', line 54 def root? parent.to_s.empty? end |
#to_s ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/tty/tree/node.rb', line 66 def to_s @name end |