Class: VimRename::FileData
- Inherits:
-
Object
- Object
- VimRename::FileData
- Defined in:
- lib/vim_rename/file_data.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #full_name ⇒ Object
-
#initialize(name, skip_extension = true) ⇒ FileData
constructor
A new instance of FileData.
- #rename! ⇒ Object
- #update(new_name) ⇒ Object
Constructor Details
#initialize(name, skip_extension = true) ⇒ FileData
Returns a new instance of FileData.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/vim_rename/file_data.rb', line 5 def initialize(name, skip_extension = true) self.name = name self.basename = if skip_extension m = name.match(/(?<extension>\.([^.]*)|\.tar\.gz|\.tar\.bz2|\.svg\.gz|\.tar\.xz)$/) self.extension = m[:extension] if m name.gsub(/#{extension}$/, '') else name end end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
4 5 6 |
# File 'lib/vim_rename/file_data.rb', line 4 def basename @basename end |
#extension ⇒ Object
Returns the value of attribute extension.
4 5 6 |
# File 'lib/vim_rename/file_data.rb', line 4 def extension @extension end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/vim_rename/file_data.rb', line 4 def name @name end |
Instance Method Details
#changed? ⇒ Boolean
24 25 26 |
# File 'lib/vim_rename/file_data.rb', line 24 def changed? full_name != name end |
#full_name ⇒ Object
20 21 22 |
# File 'lib/vim_rename/file_data.rb', line 20 def full_name "#{basename}#{extension}" end |
#rename! ⇒ Object
28 29 30 |
# File 'lib/vim_rename/file_data.rb', line 28 def rename! FileUtils.mv name, full_name end |
#update(new_name) ⇒ Object
16 17 18 |
# File 'lib/vim_rename/file_data.rb', line 16 def update(new_name) self.basename = new_name end |