Module: SC::Path
- Defined in:
- lib/sc/path.rb
Class Method Summary collapse
-
.absolute_from_home(path) ⇒ Object
convert a relative path to home to absolute.
-
.relative_to_home(path) ⇒ Object
make an absolute path relative to home.
Class Method Details
.absolute_from_home(path) ⇒ Object
convert a relative path to home to absolute
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sc/path.rb', line 30 def self.absolute_from_home (path) home = File.('~') path.strip! # path may start with ~ path = File.(path) if path[0, 1] == '~' # allow path to be relative or absolute path[0, 1] == '/' ? path : File.join(home, path) end |
.relative_to_home(path) ⇒ Object
make an absolute path relative to home
43 44 45 46 |
# File 'lib/sc/path.rb', line 43 def self.relative_to_home (path) home = File.('~') path[0, home.length] == home ? path.sub(home, '~') : path end |