Class: ExifDatify::DateExtractor

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

Constant Summary collapse

DATETIME_FORMAT =
"%Y-%m-%d_%H-%M-%S_"
DATETIME_REGEX =
/^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDateExtractor

Returns a new instance of DateExtractor.



11
12
13
14
15
# File 'lib/exif_datify.rb', line 11

def initialize
  @tags = ['DateTimeOriginal', 'MediaCreateDate']
  @quiet = false
  @counters = Hash.new(0)
end

Instance Attribute Details

#countersObject (readonly)

Returns the value of attribute counters.



7
8
9
# File 'lib/exif_datify.rb', line 7

def counters
  @counters
end

Instance Method Details

#extract_datetime(file_path) ⇒ Object



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

def extract_datetime(file_path)
  meta = exiftool(file_path)
  @tags.each do |tag|
    return DateTime.parse(meta[tag]) if meta[tag]
  end
  nil
end

#rename(file_path) ⇒ Object



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

def rename(file_path)
  @counters[:total] += 1
  unless File.basename(file_path) =~ DATETIME_REGEX
    prepend_date(file_path)
  end
end