Class: FileName
- Inherits:
-
Object
- Object
- FileName
- Defined in:
- lib/piggy-core/file_info.rb
Overview
Every String could be a Filename but we want a class containing name and path to make some things more explicit.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #extension ⇒ Object
-
#initialize(the_name, the_path = '') ⇒ FileName
constructor
A new instance of FileName.
- #name_with_path ⇒ Object
- #name_without_extension ⇒ Object
- #path_sections ⇒ Object
- #set_path(new_path) ⇒ Object
Constructor Details
#initialize(the_name, the_path = '') ⇒ FileName
Returns a new instance of FileName.
60 61 62 63 |
# File 'lib/piggy-core/file_info.rb', line 60 def initialize(the_name, the_path = '') @name = the_name set_path(the_path) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
57 58 59 |
# File 'lib/piggy-core/file_info.rb', line 57 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
58 59 60 |
# File 'lib/piggy-core/file_info.rb', line 58 def path @path end |
Instance Method Details
#extension ⇒ Object
81 82 83 |
# File 'lib/piggy-core/file_info.rb', line 81 def extension return name.split('.')[-1] end |
#name_with_path ⇒ Object
73 74 75 |
# File 'lib/piggy-core/file_info.rb', line 73 def name_with_path return FilePath.join(path, name) end |
#name_without_extension ⇒ Object
77 78 79 |
# File 'lib/piggy-core/file_info.rb', line 77 def name_without_extension return File.basename(name, '.' + extension) end |
#path_sections ⇒ Object
85 86 87 |
# File 'lib/piggy-core/file_info.rb', line 85 def path_sections return FilePath.split(path) end |
#set_path(new_path) ⇒ Object
69 70 71 |
# File 'lib/piggy-core/file_info.rb', line 69 def set_path(new_path) @path = FilePath.intern_path(new_path) end |