class Aruba::ArubaPath

Pathname for aruba files and directories

@private

Public Class Methods

new(path) click to toggle source
Calls superclass method
# File lib/aruba/aruba_path.rb, line 12
def initialize(path)
  obj = [path.to_s].flatten

  super obj

  @delegate_sd_obj = obj
end

Public Instance Methods

<<(p)
Alias for: push
[](index) click to toggle source

Return string at index

@param [Integer, Range] index

# 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__() click to toggle source

Get path

# File lib/aruba/aruba_path.rb, line 21
def __getobj__
  ::Pathname.new(::File.join(*@delegate_sd_obj))
end
__setobj__(obj) click to toggle source

Set path

# File lib/aruba/aruba_path.rb, line 26
def __setobj__(obj)
  @delegate_sd_obj = [obj.to_s].flatten
end
absolute?() click to toggle source
# File lib/aruba/aruba_path.rb, line 66
def absolute?
  (%r{\A/} === to_s)
end
blocks() click to toggle source

Report count of blocks allocated on disk

This reports the amount of blocks which are allocated by the path.

@return [Integer]

The count of blocks on disk
# File lib/aruba/aruba_path.rb, line 129
def blocks
  File::Stat.new(to_s).blocks
end
depth() click to toggle source

How many parts has the file name

@return [Integer]

The count of file name parts

@example

path = ArubaPath.new('path/to/file.txt') path.depth # => 3

# 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) click to toggle source

Path ends with string

@param [String] string

The string to check
# File lib/aruba/aruba_path.rb, line 100
def end_with?(string)
  to_s.end_with? string
end
pop() click to toggle source

Remove last component of path

@example

path = ArubaPath.new 'path/to/dir.d'
path.pop
puts path
# => path/to
# File lib/aruba/aruba_path.rb, line 53
def pop
  @delegate_sd_obj.pop
end
push(p) click to toggle source

Add directory/file to path

@param [String] p

The path to be added

@example

path = ArubaPath.new 'path/to/dir.d'
path << 'subdir.d
# or path.push 'subdir.d
puts path
# => path/to/dir.d/subdir.d
# File lib/aruba/aruba_path.rb, line 41
def push(p)
  @delegate_sd_obj << p
end
Also aliased as: <<
relative?() click to toggle source
# File lib/aruba/aruba_path.rb, line 62
def relative?
  !(%r{\A/} === to_s)
end
start_with?(string) click to toggle source

Path starts with string

@param [String] string

The string to check
# File lib/aruba/aruba_path.rb, line 108
def start_with?(string)
  to_s.start_with? string
end
to_ary() click to toggle source
# File lib/aruba/aruba_path.rb, line 70
def to_ary
  to_a
end
to_s() click to toggle source
# File lib/aruba/aruba_path.rb, line 58
def to_s
  __getobj__.to_s
end