Class: DirTravel::Entry
- Inherits:
-
Tree::TreeNode
- Object
- Tree::TreeNode
- DirTravel::Entry
- Defined in:
- lib/dirtravel.rb
Overview
Extend RubyTree base class with file and directory features.
Instance Attribute Summary (collapse)
-
- (Object) name
Returns the value of attribute name.
Instance Method Summary (collapse)
-
- (Object) abspath
Absolute path.
-
- (String) dir(basedir = self)
Relative path of parenting directory.
-
- (Object) files
Return all file entries in hierarchy.
-
- (Entry) initialize(name)
constructor
A new instance of Entry.
-
- (Array) parts(basedir = self)
(also: #pathArray)
Return path components as Array.
-
- (Object) path
Relative path.
-
- (Boolean) relative?
Relative path Entry.
-
- (Object) rename(name)
Rename node.
-
- (Array) select_level(level)
Select all siblings from given node depth.
-
- (Object) stat
File.stat data for the Entry.
-
- (Object) subpath(level = 1)
Relative path under root.
-
- (Object) tip
Top directory name (usually same as name).
Constructor Details
- (Entry) initialize(name)
A new instance of Entry
49 50 51 52 |
# File 'lib/dirtravel.rb', line 49 def initialize( name ) super( name, nil ) @abspath = nil end |
Instance Attribute Details
- (Object) name
Returns the value of attribute name
47 48 49 |
# File 'lib/dirtravel.rb', line 47 def name @name end |
Instance Method Details
- (Object) abspath
Absolute path.
90 91 92 93 94 95 96 |
# File 'lib/dirtravel.rb', line 90 def abspath if @abspath @abspath else root.abspath + '/' + subpath end end |
- (String) dir(basedir = self)
Relative path of parenting directory.
109 110 111 |
# File 'lib/dirtravel.rb', line 109 def dir( basedir = self ) parts( basedir.parent ).join( '/' ) end |
- (Object) files
Return all file entries in hierarchy.
125 126 127 |
# File 'lib/dirtravel.rb', line 125 def files select do |i| i.kind_of?( FileEntry ) end end |
- (Array) parts(basedir = self) Also known as: pathArray
Return path components as Array.
59 60 61 62 63 64 65 66 |
# File 'lib/dirtravel.rb', line 59 def parts( basedir = self ) parents = [] while basedir parents.push basedir.tip basedir = basedir.parent end parents.reverse end |
- (Object) path
Relative path.
72 73 74 |
# File 'lib/dirtravel.rb', line 72 def path parts.join( '/' ) end |
- (Boolean) relative?
Relative path Entry.
136 137 138 |
# File 'lib/dirtravel.rb', line 136 def relative? @name[0] != '/' end |
- (Object) rename(name)
Rename node.
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/dirtravel.rb', line 144 def rename( name ) @name = name # Absolute or relative path? if name[0] == "/" @abspath = name else @abspath = nil end end |
- (Array) select_level(level)
Select all siblings from given node depth.
119 120 121 |
# File 'lib/dirtravel.rb', line 119 def select_level( level ) select do |i| i.node_depth == level; end end |
- (Object) stat
File.stat data for the Entry.
131 132 133 |
# File 'lib/dirtravel.rb', line 131 def stat File.stat( path ) end |
- (Object) subpath(level = 1)
Relative path under root.
80 81 82 83 84 85 86 |
# File 'lib/dirtravel.rb', line 80 def subpath( level = 1 ) pa = parts if level < 0 || level > pa.length raise DirTravelError, "Invalid index for subpath level!" end pa[ level .. -1 ].join( '/' ) end |
- (Object) tip
Top directory name (usually same as name).
100 101 102 |
# File 'lib/dirtravel.rb', line 100 def tip @name.split( "/" )[-1] end |