Class: WindowsPathArray

Inherits:
Array
  • Object
show all
Defined in:
lib/windows_path.rb

Overview

Specialized array that knows how to compare paths.

Instance Method Summary collapse

Instance Method Details

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



20
21
22
# File 'lib/windows_path.rb', line 20

def <<(p)
  super(p.to_s)
end

#[](idx) ⇒ Object



39
40
41
# File 'lib/windows_path.rb', line 39

def [](idx)
	WindowsPath.expand_vars(super)
end

#compare_paths(left, right) ⇒ Object



13
14
15
16
17
18
# File 'lib/windows_path.rb', line 13

def compare_paths(left, right)
  left = Pathname.new(WindowsPath.expand_vars(left.to_s).downcase).cleanpath
  right = Pathname.new(WindowsPath.expand_vars(right.to_s).downcase).cleanpath
  
  return left.eql?(right)
end

#delete(path) ⇒ Object



26
27
28
# File 'lib/windows_path.rb', line 26

def delete(path)
	self.delete_if { |p| compare_paths(path, p) }
end

#eachObject



30
31
32
33
34
# File 'lib/windows_path.rb', line 30

def each
	for i in 0..size - 1
		yield WindowsPath.expand_vars(raw_item(i))
	end
end

#include?(path) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/windows_path.rb', line 7

def include?(path)
   # Compare paths case-insensitive, and also checking
   # trailing separators (so c:\program files == c:\program files\)
   self.any? { |p| compare_paths(path, p) }
end

#raw_itemObject

Preserve access to base class definition of []



37
# File 'lib/windows_path.rb', line 37

alias_method :raw_item, :[]