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.



11
12
13
# File 'lib/aruba/aruba_path.rb', line 11

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

Instance Method Details

#[](index) ⇒ Object

Return string at index

Parameters:

  • index (Integer, Range)


53
54
55
# File 'lib/aruba/aruba_path.rb', line 53

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


46
47
48
# File 'lib/aruba/aruba_path.rb', line 46

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



34
35
36
# File 'lib/aruba/aruba_path.rb', line 34

def push(p)
  @obj << p
end

#to_sObject



19
20
21
# File 'lib/aruba/aruba_path.rb', line 19

def to_s
  to_str
end

#to_strObject



15
16
17
# File 'lib/aruba/aruba_path.rb', line 15

def to_str
  to_pathname.to_s
end