Class: Mdtoc::Node
- Inherits:
-
Object
- Object
- Mdtoc::Node
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/mdtoc/node.rb
Class Method Summary collapse
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(path, depth) ⇒ Node
constructor
A new instance of Node.
- #label ⇒ Object
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
#headers ⇒ Object
35 |
# File 'lib/mdtoc/node.rb', line 35 def headers; end |
#label ⇒ Object
30 31 32 |
# File 'lib/mdtoc/node.rb', line 30 def label File.basename(@path, File.extname(@path)).gsub(/_+/, ' ').gsub(/\s+/, ' ').capitalize end |