Class: Mdtoc::Node
- Inherits:
-
Object
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/mdtoc/node.rb
Defined Under Namespace
Classes: DirNode, FileNode
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path, depth) ⇒ Node
Returns a new instance of Node.
37
38
39
40
|
# File 'lib/mdtoc/node.rb', line 37
def initialize(path, depth)
@path = path
@depth = depth
end
|
Class Method Details
.for_path(path, depth = 0) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/mdtoc/node.rb', line 20
def for_path(path, depth = 0)
pathname = Pathname.new(path)
pathname = pathname.relative_path_from(Dir.pwd) if pathname.absolute?
pathname.directory? ? DirNode.new(pathname, depth) : FileNode.new(pathname, depth)
end
|
.render(paths) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/mdtoc/node.rb', line 28
def render(paths)
= paths.flat_map { |path| for_path(path). }
min_depth = .map(&:depth).min || 0
.each { |h| h.depth -= min_depth } if min_depth.positive?
.join("\n")
end
|
Instance Method Details
43
|
# File 'lib/mdtoc/node.rb', line 43
def ; end
|
#label ⇒ Object
46
47
48
|
# File 'lib/mdtoc/node.rb', line 46
def label
@path.basename(@path.extname).to_s.gsub(/_+/, ' ').gsub(/\s+/, ' ').capitalize
end
|