Class: Mdtoc::Node

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/mdtoc/node.rb

Direct Known Subclasses

DirNode, FileNode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, depth) ⇒ Node

Returns a new instance of Node.



24
25
26
27
# File 'lib/mdtoc/node.rb', line 24

def initialize(path, depth)
  @path = path
  @depth = depth
end

Class Method Details

.for_path(path, depth = 0) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/mdtoc/node.rb', line 15

def self.for_path(path, depth = 0)
  # Ensure that `path` is a relative path, so that all links are relative and therefore portable.
  path = Pathname.new(path)
  path = path.relative_path_from(Dir.pwd) if path.absolute?
  path = path.to_s
  File.directory?(path) ? DirNode.new(path, depth) : FileNode.new(path, depth)
end

Instance Method Details

#headersObject



35
# File 'lib/mdtoc/node.rb', line 35

def headers; end

#labelObject



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

def label
  File.basename(@path, File.extname(@path)).gsub(/_+/, ' ').gsub(/\s+/, ' ').capitalize
end