Class: Pathname
- Inherits:
-
Object
- Object
- Pathname
- Defined in:
- lib/masterview/core_ext/pathname.rb
Direct Known Subclasses
Class Method Summary collapse
-
.for_path(path) ⇒ Object
create a new Pathname object for path, any backslashes are converted to /, if Pathname object is passed in then returns this existing pathname object.
-
.join(*args) ⇒ Object
return the concatenated path, cleaning up any backslashes, ignores nulls or empty pathnames.
-
.safe_concat(prepend_pn, pathname) ⇒ Object
prepends a pathname to existing, ignores nulls or empty pathnames.
Instance Method Summary collapse
-
#path_no_ext ⇒ Object
return the path string without the extension.
Class Method Details
.for_path(path) ⇒ Object
create a new Pathname object for path, any backslashes are converted to /, if Pathname object is passed in then returns this existing pathname object
6 7 8 9 |
# File 'lib/masterview/core_ext/pathname.rb', line 6 def self.for_path(path) return path if path.is_a? Pathname Pathname.new(path.gsub('\\','/')) end |
.join(*args) ⇒ Object
return the concatenated path, cleaning up any backslashes, ignores nulls or empty pathnames
12 13 14 15 |
# File 'lib/masterview/core_ext/pathname.rb', line 12 def self.join(*args) pathnames = args.collect { |a| Pathname.for_path(a) } pathnames.inject { |fullpath, p| self.safe_concat(fullpath, p) } end |
.safe_concat(prepend_pn, pathname) ⇒ Object
prepends a pathname to existing, ignores nulls or empty pathnames
18 19 20 21 22 23 |
# File 'lib/masterview/core_ext/pathname.rb', line 18 def self.safe_concat(prepend_pn, pathname) return nil if ((prepend_pn.nil? || prepend_pn.to_s.empty?) && (pathname.nil? || pathname.to_s.empty?)) #both are nil or empty return prepend_pn if (pathname.nil? || pathname.to_s.empty?) return pathname if (prepend_pn.nil? || prepend_pn.to_s.empty?) prepend_pn+pathname end |
Instance Method Details
#path_no_ext ⇒ Object
return the path string without the extension
26 27 28 29 30 31 32 |
# File 'lib/masterview/core_ext/pathname.rb', line 26 def path_no_ext dirname = self.dirname ext = self.extname base = self.basename(ext) presult = (dirname.to_s.empty?) ? base : dirname+base presult.to_s end |