Class: FileRenamer::Path
- Inherits:
-
Object
- Object
- FileRenamer::Path
- Defined in:
- lib/path.rb
Constant Summary collapse
- FILENAME_REGEX =
/([^\/|\\]+$)/- @@counter =
0
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#new_name ⇒ Object
readonly
Returns the value of attribute new_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #correct_path? ⇒ Boolean
-
#initialize(path, params) ⇒ Path
constructor
A new instance of Path.
- #rename_file! ⇒ Object
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
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
8 9 10 |
# File 'lib/path.rb', line 8 def ext @ext end |
#new_name ⇒ Object (readonly)
Returns the value of attribute new_name.
8 9 10 |
# File 'lib/path.rb', line 8 def new_name @new_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/path.rb', line 8 def path @path end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/path.rb', line 8 def prefix @prefix end |
Class Method Details
.get_count ⇒ Object
10 11 12 |
# File 'lib/path.rb', line 10 def self.get_count @@counter end |
.reset_counter ⇒ Object
14 15 16 |
# File 'lib/path.rb', line 14 def self.reset_counter @@counter = 0 end |
Instance Method Details
#correct_path? ⇒ 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 |