Sha256: c6ea3c75dd9142c3ee8a054cb7133667b388cedea612ad29e6e1df6c16b3bfe0

Contents?: true

Size: 721 Bytes

Versions: 8

Compression:

Stored size: 721 Bytes

Contents

class String  
  def path
    self.extend PathString
  end      
end

module PathString
  def exists?  
    File.exist? self
  end

  def file?  
    File.file? self
  end

  def dir?  
    File.directory? self
  end

  def symlink?  
    File.symlink? self
  end
  
  def up lv
    ('../' * lv) + self
  end

  def post_up lv
    self + ('/..' * lv)
  end

  def post_down lv
    up_dir = Regexp.escape('/..')
    orig = self.clone
    lv.times do
      self.gsub! /#{up_dir}$/, ''
      return self if self == orig
    end
    self
  end

  def down lv
    up_dir = Regexp.escape('../')
    orig = self.clone
    lv.times do
      self.gsub! /^#{up_dir}/, ''
      return self if self == orig
    end
    self
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sugar-high-0.3.3 lib/sugar-high/path.rb
sugar-high-0.3.2 lib/sugar-high/path.rb
sugar-high-0.3.1 lib/sugar-high/path.rb
sugar-high-0.3.0 lib/sugar-high/path.rb
sugar-high-0.2.12 lib/sugar-high/path.rb
sugar-high-0.2.11 lib/sugar-high/path.rb
sugar-high-0.2.10 lib/sugar-high/path.rb
sugar-high-0.2.9 lib/sugar-high/path.rb