Class: Roto
- Inherits:
-
Object
- Object
- Roto
- Defined in:
- lib/roto.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#files ⇒ Object
Returns the value of attribute files.
-
#rename_duplicates ⇒ Object
Returns the value of attribute rename_duplicates.
-
#types ⇒ Object
Returns the value of attribute types.
Instance Method Summary collapse
- #copy_files(destination) ⇒ Object
- #find_files(path) ⇒ Object
-
#initialize ⇒ Roto
constructor
A new instance of Roto.
- #move_files(destination) ⇒ Object
Constructor Details
#initialize ⇒ Roto
Returns a new instance of Roto.
10 11 12 13 14 15 16 |
# File 'lib/roto.rb', line 10 def initialize @files = [] @types = ['.mp4', '.mov', '.jpg', '.png', '.mts'] @rename_duplicates = true @errors = {} @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/roto.rb', line 8 def errors @errors end |
#files ⇒ Object
Returns the value of attribute files.
7 8 9 |
# File 'lib/roto.rb', line 7 def files @files end |
#rename_duplicates ⇒ Object
Returns the value of attribute rename_duplicates.
7 8 9 |
# File 'lib/roto.rb', line 7 def rename_duplicates @rename_duplicates end |
#types ⇒ Object
Returns the value of attribute types.
7 8 9 |
# File 'lib/roto.rb', line 7 def types @types end |
Instance Method Details
#copy_files(destination) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/roto.rb', line 50 def copy_files(destination) = ProgressBar.create(total: @files.count, format: '%a %B %p%% %t') @files.each do |file| filename = File.basename(file) ext = File.extname(file) name = File.basename(file, ext) begin if File.exist?("#{destination}/#{filename}") && @rename_duplicates FileUtils.cp("#{file}", "#{destination}/#{name}_#{Time.now.to_i}#{ext}") else FileUtils.cp("#{file}", "#{destination}") end .increment rescue => error @errors[file] = error end end end |
#find_files(path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/roto.rb', line 18 def find_files(path) = ProgressBar.create(total: nil, format: "%a Finding Files") Find.find(path).each do |file| if @types.include?(File.extname(file).downcase) @files << file .increment end end @logger.info("Found: #{@files.count} files") self end |
#move_files(destination) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/roto.rb', line 30 def move_files(destination) = ProgressBar.create(total: @files.count, format: '%a %B %p%% %t') @files.each do |file| filename = File.basename(file) ext = File.extname(file) name = File.basename(file, ext) begin if File.exist?("#{destination}/#{filename}") && @rename_duplicates FileUtils.mv("#{file}", "#{destination}/#{name}_#{Time.now.to_i}#{ext}") else FileUtils.mv("#{file}", "#{destination}") end .increment rescue => error @errors[file] = error end end self end |