Class: VimRename::FileData

Inherits:
Object
  • Object
show all
Defined in:
lib/vim_rename/file_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#basenameObject

Returns the value of attribute basename.



4
5
6
# File 'lib/vim_rename/file_data.rb', line 4

def basename
  @basename
end

#extensionObject

Returns the value of attribute extension.



4
5
6
# File 'lib/vim_rename/file_data.rb', line 4

def extension
  @extension
end

#nameObject

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/vim_rename/file_data.rb', line 24

def changed?
  full_name != name
end

#full_nameObject



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