Class: TTY::Tree::Node Private

Inherits:
Object
  • Object
show all
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

LeafNode

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



36
37
38
39
40
41
42
# File 'lib/tty/tree/node.rb', line 36

def initialize(path, parent, prefix, level)
  @path   = Pathname.new(path)
  @name   = @path.basename
  @parent = Pathname.new(parent)
  @prefix = prefix
  @level  = level
end

Instance Attribute Details

#levelObject (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



25
26
27
# File 'lib/tty/tree/node.rb', line 25

def level
  @level
end

#nameObject (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



16
17
18
# File 'lib/tty/tree/node.rb', line 16

def name
  @name
end

#parentObject (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



19
20
21
# File 'lib/tty/tree/node.rb', line 19

def parent
  @parent
end

#pathObject (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



31
32
33
# File 'lib/tty/tree/node.rb', line 31

def path
  @path
end

#prefixObject (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



22
23
24
# File 'lib/tty/tree/node.rb', line 22

def prefix
  @prefix
end

#statObject (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



28
29
30
# File 'lib/tty/tree/node.rb', line 28

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.



65
66
67
# File 'lib/tty/tree/node.rb', line 65

def ==(other)
  other.is_a?(self.class) && other.state_attrs == state_attrs
end

#full_pathObject

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.



44
45
46
47
# File 'lib/tty/tree/node.rb', line 44

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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/tty/tree/node.rb', line 53

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.

Returns:

  • (Boolean)


57
58
59
# File 'lib/tty/tree/node.rb', line 57

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.

Returns:

  • (Boolean)


49
50
51
# File 'lib/tty/tree/node.rb', line 49

def root?
  parent.to_s.empty?
end

#to_sObject

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.



61
62
63
# File 'lib/tty/tree/node.rb', line 61

def to_s
  @name
end