Class: Aruba::ArubaPath

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/aruba_path.rb

Overview

Pathname for aruba files and directories

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ArubaPath

Returns a new instance of ArubaPath.



9
10
11
# File 'lib/aruba/aruba_path.rb', line 9

def initialize(path)
  @obj = [path.to_s].flatten
end

Instance Method Details

#[](index) ⇒ Object

Return string at index

Parameters:

  • index (Integer, Range)


51
52
53
# File 'lib/aruba/aruba_path.rb', line 51

def [](index)
  to_s[index]
end

#popObject

Remove last pushed component of path

Examples:

path = ArubaPath.new 'path/to'
path.push 'dir'
path.pop
puts path # => path/to


44
45
46
# File 'lib/aruba/aruba_path.rb', line 44

def pop
  @obj.pop
end

#push(p) ⇒ Object Also known as: <<

Add directory/file to path

Examples:

path = ArubaPath.new 'path/to/dir.d'
path << 'subdir.d
# or path.push 'subdir.d
puts path
# => path/to/dir.d/subdir.d

Parameters:

  • p (String)

    The path to be added



32
33
34
# File 'lib/aruba/aruba_path.rb', line 32

def push(p)
  @obj << p
end

#to_sObject



17
18
19
# File 'lib/aruba/aruba_path.rb', line 17

def to_s
  to_str
end

#to_strObject



13
14
15
# File 'lib/aruba/aruba_path.rb', line 13

def to_str
  to_pathname.to_s
end