Class: Filename
- Inherits:
-
Object
- Object
- Filename
- Defined in:
- lib/filename.rb
Constant Summary collapse
- DIR_SEPARATOR =
'/'
- WINDOWS_DIR_SEPARATOR =
'\\'
Instance Attribute Summary collapse
-
#path_items ⇒ Object
Returns the value of attribute path_items.
Instance Method Summary collapse
- #absolute_path? ⇒ Boolean
- #extract_last_path_item ⇒ Object
-
#initialize(filename) ⇒ Filename
constructor
A new instance of Filename.
- #relative_path? ⇒ Boolean
- #remove_last_path_item ⇒ Object
- #to_s ⇒ Object
- #to_unix_s ⇒ Object
- #to_windows_s ⇒ Object
- #without_extension ⇒ Object
Constructor Details
#initialize(filename) ⇒ Filename
Returns a new instance of Filename.
8 9 10 11 12 |
# File 'lib/filename.rb', line 8 def initialize filename filename = filename.gsub(WINDOWS_DIR_SEPARATOR, DIR_SEPARATOR) @path_items = filename.split(DIR_SEPARATOR).delete_if{|item| item.empty?} @absolute_path = filename.start_with? DIR_SEPARATOR end |
Instance Attribute Details
#path_items ⇒ Object
Returns the value of attribute path_items.
6 7 8 |
# File 'lib/filename.rb', line 6 def path_items @path_items end |
Instance Method Details
#absolute_path? ⇒ Boolean
14 15 16 |
# File 'lib/filename.rb', line 14 def absolute_path? @absolute_path end |
#extract_last_path_item ⇒ Object
30 31 32 |
# File 'lib/filename.rb', line 30 def extract_last_path_item Filename.new(nil_to_empty_string @path_items.last) end |
#relative_path? ⇒ Boolean
18 19 20 |
# File 'lib/filename.rb', line 18 def relative_path? not absolute_path? end |
#remove_last_path_item ⇒ Object
34 35 36 |
# File 'lib/filename.rb', line 34 def remove_last_path_item Filename.new(make_string(@path_items[0..-2])) end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/filename.rb', line 46 def to_s to_unix_s end |
#to_unix_s ⇒ Object
38 39 40 |
# File 'lib/filename.rb', line 38 def to_unix_s make_string @path_items end |
#to_windows_s ⇒ Object
42 43 44 |
# File 'lib/filename.rb', line 42 def to_windows_s make_string @path_items, WINDOWS_DIR_SEPARATOR end |