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.



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

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



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

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



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

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



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

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



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

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



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

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



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.



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

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.



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

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)


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

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)


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

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)


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

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.



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

def to_s
  @name
end