Class: Pathname
- Inherits:
-
Object
- Object
- Pathname
- Defined in:
- lib/lsync/directory.rb
Instance Method Summary collapse
-
#components ⇒ Object
Split a pathname up based on the individual path components.
-
#depth ⇒ Object
Returns the number of path components in a normalised fashion.
-
#normalize_trailing_slash ⇒ Object
Add a trailing slash to the path if it doesn’t already exist.
Instance Method Details
#components ⇒ Object
Split a pathname up based on the individual path components.
27 28 29 |
# File 'lib/lsync/directory.rb', line 27 def components return to_s.split(SEPARATOR_PAT) end |
#depth ⇒ Object
Returns the number of path components in a normalised fashion.
We need to work with a cleanpath to get an accurate depth: “”, “/” => 0 “bob” => 1 “bob/dole” => 2 “/bob/dole” => 2
47 48 49 50 51 52 53 54 |
# File 'lib/lsync/directory.rb', line 47 def depth bits = cleanpath.to_s.split(SEPARATOR_PAT) bits.delete("") bits.delete(".") return bits.size end |
#normalize_trailing_slash ⇒ Object
Add a trailing slash to the path if it doesn’t already exist.
32 33 34 35 36 37 38 |
# File 'lib/lsync/directory.rb', line 32 def normalize_trailing_slash if to_s.match(/\/$/) return self else return self.class.new(to_s + "/") end end |