class PhTools::Phfixdto

Public Class Methods

about() click to toggle source
# File lib/phfixdto.rb, line 12
def self.about
  'fixes DateTimeOriginal tag to be equal to date-time-in-the-name'
end

Private Instance Methods

process_after() click to toggle source
# File lib/phfixdto.rb, line 59
def process_after
  @writer.run! unless @options_cli['--no_run']
end
process_before() click to toggle source
# File lib/phfixdto.rb, line 18
def process_before
  @writer = ExifTagger::TagWriter.new(
    script_name: 'exif_tagger_dto.txt',
    memo: "#{DateTime.now}: Script generated by #{@tool_name} version #{PhTools::VERSION})",
    output: STDERR
  )
end
process_file(phfile) click to toggle source
# File lib/phfixdto.rb, line 26
def process_file(phfile)
  fail PhTools::Error, 'wrong date-time-in-the-name' unless phfile.date_time_ok?

  STDERR.puts %(  ...#{phfile}...)
  begin
    @tags_original = MiniExiftool.new(phfile.filename,
                                      replace_invalid_chars: true,
                                      composite: true,
                                      timestamps: DateTime)
  rescue
    raise PhTools::Error, "EXIF tags reading - #{e.message}"
  end

  @tags_to_write = ExifTagger::TagCollection.new

  @tags_to_write[:date_time_original] = phfile.date_time_to_time
  @tags_to_write.item(:date_time_original).force_write = true

  unless @tags_original[:create_date].nil?
    @tags_to_write[:create_date] = phfile.date_time_to_time
    @tags_to_write.item(:create_date).force_write = true
  end
  @tags_to_write.check_for_warnings(original_values: @tags_original)
  fail PhTools::Error, @tags_to_write.error_message unless @tags_to_write.valid?

  @writer.add_to_script(filename: phfile, tags: @tags_to_write)

  return ''

rescue => e
  raise PhTools::Error, e.message
end