Class: ExifDatify::DateExtractor
- Inherits:
-
Object
- Object
- ExifDatify::DateExtractor
- 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
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
-
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #copy!(destination) ⇒ Object
- #extract_datetime(file_path) ⇒ Object
-
#initialize ⇒ DateExtractor
constructor
A new instance of DateExtractor.
- #month_subdirectories! ⇒ Object
- #move!(destination) ⇒ Object
- #process(file_path) ⇒ Object
- #quiet! ⇒ Object
- #rename! ⇒ Object
Constructor Details
#initialize ⇒ DateExtractor
Returns a new instance of DateExtractor.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/exif_datify.rb', line 13 def initialize @logger = Logger.new(STDOUT) @logger.level = Logger::WARN @tags = ['DateTimeOriginal', 'MediaCreateDate'] @datetime_format = "%Y-%m-%d_%H-%M-%S_" @quiet = false @counters = Hash.new(0) rename! @month_subdirectories = false end |
Instance Attribute Details
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
9 10 11 |
# File 'lib/exif_datify.rb', line 9 def counters @counters end |
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
10 11 12 |
# File 'lib/exif_datify.rb', line 10 def datetime_format @datetime_format end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/exif_datify.rb', line 9 def logger @logger end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
9 10 11 |
# File 'lib/exif_datify.rb', line 9 def operation @operation end |
#tags ⇒ Object
Returns the value of attribute tags.
10 11 12 |
# File 'lib/exif_datify.rb', line 10 def @tags end |
Instance Method Details
#copy!(destination) ⇒ Object
42 43 44 45 46 |
# File 'lib/exif_datify.rb', line 42 def copy!(destination) raise "#{destination} does not exist" unless FileTest.directory?(destination) @operation = :copy @destination = destination end |
#extract_datetime(file_path) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/exif_datify.rb', line 48 def extract_datetime(file_path) @logger.debug "Extracting datetime from #{file_path}" = exiftool(file_path) @tags.each do |tag| return DateTime.parse([tag]) if [tag] end nil end |
#month_subdirectories! ⇒ Object
28 29 30 |
# File 'lib/exif_datify.rb', line 28 def month_subdirectories! @month_subdirectories = true end |
#move!(destination) ⇒ Object
36 37 38 39 40 |
# File 'lib/exif_datify.rb', line 36 def move!(destination) raise "#{destination} does not exist" unless FileTest.directory?(destination) @operation = :move @destination = destination end |
#process(file_path) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/exif_datify.rb', line 57 def process(file_path) @counters[:total] += 1 datetime = extract_datetime(file_path) if datetime.nil? puts "Could not extract date from #{current_name}" unless @quiet else operate(file_path, datetime) end end |
#quiet! ⇒ Object
24 25 26 |
# File 'lib/exif_datify.rb', line 24 def quiet! @quiet = true end |
#rename! ⇒ Object
32 33 34 |
# File 'lib/exif_datify.rb', line 32 def rename! @operation = :rename end |