Top Level Namespace

Defined Under Namespace

Modules: Imagelib Classes: Copy

Constant Summary collapse

HOME =
ENV['HOME']
OUT_DIR =
"#{HOME}/Pictures/ImageLib"
PATTERN =
'**/*.{jpg,JPG,avi,AVI,wav,WAV,CR2}'

Instance Method Summary collapse

Instance Method Details

#collect_images(configs) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/imagelib/copy2lib.rb', line 52

def collect_images(configs)
  images = []
  configs.each do |config|
    path = config['path'].strip
    files = Dir.glob("#{path}/#{PATTERN}")
    files.each do |file|
      images << Copy.new(file, config['prefix'])
    end
  end
  return images
end

#copy_images(images) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/imagelib/copy2lib.rb', line 65

def copy_images(images)
  progress = ProgressBar.new("copy #{images.length} files", images.size)
  copied_images = Array.new
  images.each do | copy |
    copy.prepare
    res = copy.copy
    if res
      copied_images << res
    end
    progress.inc
  end
  progress.finish
  return copied_images
end

#copy_to_lib(args) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/imagelib/copy2lib.rb', line 102

def copy_to_lib(args)
  configs = process_commandline(args)
  images = collect_images(configs)
  images = images.sort{ |a,b| a.filename <=> b.filename }
  images = images.select{ |copy| copy.work_to_do? }
  copied_images = copy_images(images)
  report_result(copied_images)
end

#process_commandline(args) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/imagelib/copy2lib.rb', line 80

def process_commandline(args)
  configs = []
  if (args.size == 0) then
    configs = YAML::load_file("#{HOME}/.imagelib")
  else
    i = 0
    while i < args.size
      path = args[i]
      prefix = args[i+1]
      configs << {'path' => path, 'prefix' => prefix}
      i = i + 2
    end
  end
end

#report_result(copied_images) ⇒ Object



95
96
97
98
99
100
# File 'lib/imagelib/copy2lib.rb', line 95

def report_result(copied_images)
  puts "copied images: #{copied_images.size}"
  copied_images.sort.each do | i |
    puts "copied #{i}"
  end
end