Class: Aruba::ArubaPath
- Inherits:
-
Delegator
- Object
- Delegator
- Aruba::ArubaPath
- Defined in:
- lib/aruba/aruba_path.rb
Overview
Pathname for aruba files and directories
Instance Method Summary collapse
-
#[](index) ⇒ Object
Return string at index.
-
#__getobj__ ⇒ Object
Get path.
-
#__setobj__(obj) ⇒ Object
Set path.
- #absolute? ⇒ Boolean
-
#blocks ⇒ Integer
Report count of blocks allocated on disk.
-
#depth ⇒ Integer
How many parts has the file name.
-
#end_with?(string) ⇒ Boolean
Path ends with string.
-
#initialize(path) ⇒ ArubaPath
constructor
A new instance of ArubaPath.
-
#pop ⇒ Object
Remove last component of path.
-
#push(p) ⇒ Object
(also: #<<)
Add directory/file to path.
- #relative? ⇒ Boolean
-
#start_with?(string) ⇒ Boolean
Path starts with string.
- #to_ary ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ ArubaPath
Returns a new instance of ArubaPath.
12 13 14 15 16 17 18 |
# File 'lib/aruba/aruba_path.rb', line 12 def initialize(path) obj = [path.to_s].flatten super obj @delegate_sd_obj = obj end |
Instance Method Details
#[](index) ⇒ Object
Return string at index
115 116 117 118 119 120 121 |
# File 'lib/aruba/aruba_path.rb', line 115 def [](index) if RUBY_VERSION < '1.9' to_s.chars.to_a[index].to_a.join('') else to_s[index] end end |
#__getobj__ ⇒ Object
Get path
21 22 23 |
# File 'lib/aruba/aruba_path.rb', line 21 def __getobj__ ::Pathname.new(::File.join(*@delegate_sd_obj)) end |
#__setobj__(obj) ⇒ Object
Set path
26 27 28 |
# File 'lib/aruba/aruba_path.rb', line 26 def __setobj__(obj) @delegate_sd_obj = [obj.to_s].flatten end |
#absolute? ⇒ Boolean
66 67 68 |
# File 'lib/aruba/aruba_path.rb', line 66 def absolute? (%r{\A/} === to_s) end |
#blocks ⇒ Integer
Report count of blocks allocated on disk
This reports the amount of blocks which are allocated by the path.
129 130 131 |
# File 'lib/aruba/aruba_path.rb', line 129 def blocks File::Stat.new(to_s).blocks end |
#depth ⇒ Integer
How many parts has the file name
path = ArubaPath.new('path/to/file.txt') path.depth # => 3
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aruba/aruba_path.rb', line 85 def depth if RUBY_VERSION < '1.9' items = [] __getobj__.each_filename { |f| items << f } items.size else __getobj__.each_filename.to_a.size end end |
#end_with?(string) ⇒ Boolean
Path ends with string
100 101 102 |
# File 'lib/aruba/aruba_path.rb', line 100 def end_with?(string) to_s.end_with? string end |
#pop ⇒ Object
Remove last component of path
53 54 55 |
# File 'lib/aruba/aruba_path.rb', line 53 def pop @delegate_sd_obj.pop end |
#push(p) ⇒ Object Also known as: <<
Add directory/file to path
41 42 43 |
# File 'lib/aruba/aruba_path.rb', line 41 def push(p) @delegate_sd_obj << p end |
#relative? ⇒ Boolean
62 63 64 |
# File 'lib/aruba/aruba_path.rb', line 62 def relative? !(%r{\A/} === to_s) end |
#start_with?(string) ⇒ Boolean
Path starts with string
108 109 110 |
# File 'lib/aruba/aruba_path.rb', line 108 def start_with?(string) to_s.start_with? string end |
#to_ary ⇒ Object
70 71 72 |
# File 'lib/aruba/aruba_path.rb', line 70 def to_ary to_a end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/aruba/aruba_path.rb', line 58 def to_s __getobj__.to_s end |