Class: Gitdocs::Docfile

Inherits:
Object
  • Object
show all
Defined in:
lib/gitdocs/docfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Docfile

Returns a new instance of Docfile.



6
7
8
9
10
# File 'lib/gitdocs/docfile.rb', line 6

def initialize(path)
  @path = path
  @parent = File.dirname(path)
  @name = File.basename(path)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/gitdocs/docfile.rb', line 4

def name
  @name
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/gitdocs/docfile.rb', line 3

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/gitdocs/docfile.rb', line 4

def path
  @path
end

Instance Method Details

#dir?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/gitdocs/docfile.rb', line 19

def dir?
  File.directory?(@path)
end

#within?(dir, root) ⇒ Boolean

within?(“parent”, “/root/path”) => “/root/path/parent”

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/gitdocs/docfile.rb', line 13

def within?(dir, root)
  expanded_root = File.expand_path(dir, root)
  File.expand_path(@parent, root) == expanded_root ||
    File.expand_path(@path, root).include?(expanded_root)
end