Class: ExifDateSorter
- Inherits:
-
Object
- Object
- ExifDateSorter
- Defined in:
- lib/exif-date-sorter.rb,
lib/exif-date-sorter/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #date(image) ⇒ Object
- #dir(image) ⇒ Object
-
#initialize(source, target) ⇒ ExifDateSorter
constructor
A new instance of ExifDateSorter.
- #move ⇒ Object
Constructor Details
#initialize(source, target) ⇒ ExifDateSorter
Returns a new instance of ExifDateSorter.
6 7 8 9 |
# File 'lib/exif-date-sorter.rb', line 6 def initialize(source, target) @source = source @target = target end |
Instance Method Details
#date(image) ⇒ Object
19 20 21 |
# File 'lib/exif-date-sorter.rb', line 19 def date(image) EXIFR::JPEG.new(image).date_time_original end |
#dir(image) ⇒ Object
23 24 25 26 |
# File 'lib/exif-date-sorter.rb', line 23 def dir(image) date = date(image) "#{@target}/#{date.year}/#{'%02d' % date.month}" end |
#move ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/exif-date-sorter.rb', line 11 def move Dir[@source + '/**/*.{jpg,JPG}'].each do |image| target_dir = dir(image) FileUtils.mkdir_p(target_dir) unless File.directory? target_dir FileUtils.move image, target_dir end end |