Class: ExifDatify::DateExtractor

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

Constant Summary collapse

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
16
# File 'lib/exif_datify.rb', line 11

def initialize
  @tags = ['DateTimeOriginal', 'MediaCreateDate']
  @datetime_format = "%Y-%m-%d_%H-%M-%S_"
  @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

#datetime_formatObject

Returns the value of attribute datetime_format.



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

def datetime_format
  @datetime_format
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#extract_datetime(file_path) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/exif_datify.rb', line 22

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

#quiet!Object



18
19
20
# File 'lib/exif_datify.rb', line 18

def quiet!
  @quiet = true
end

#rename(file_path) ⇒ Object



30
31
32
33
34
35
# File 'lib/exif_datify.rb', line 30

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