Class: FileRenamer::Path

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

Constant Summary collapse

FILENAME_REGEX =
/([^\/|\\]+$)/
@@counter =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, params) ⇒ Path

Returns a new instance of Path.



18
19
20
21
22
23
# File 'lib/path.rb', line 18

def initialize(path, params)
  @path = path
  @new_name = params[:name] 
  @prefix = params[:prefix]
  @ext = params[:ext]
end

Instance Attribute Details

#extObject (readonly)

Returns the value of attribute ext.



8
9
10
# File 'lib/path.rb', line 8

def ext
  @ext
end

#new_nameObject (readonly)

Returns the value of attribute new_name.



8
9
10
# File 'lib/path.rb', line 8

def new_name
  @new_name
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/path.rb', line 8

def path
  @path
end

#prefixObject (readonly)

Returns the value of attribute prefix.



8
9
10
# File 'lib/path.rb', line 8

def prefix
  @prefix
end

Class Method Details

.get_countObject



10
11
12
# File 'lib/path.rb', line 10

def self.get_count 
  @@counter 
end

.reset_counterObject



14
15
16
# File 'lib/path.rb', line 14

def self.reset_counter
  @@counter = 0
end

Instance Method Details

#correct_path?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/path.rb', line 25

def correct_path?
  @path.slice(FILENAME_REGEX)
  .match?(Regexp.new("^#{prefix}.*#{ext}$")) && 
  !File.directory?(@path)
end

#rename_file!Object



31
32
33
34
# File 'lib/path.rb', line 31

def rename_file!
  File.rename(@path, renamed_path(@@counter))
  @@counter += 1 
end