Class: ExifTagger::TagWriter
- Inherits:
-
Object
- Object
- ExifTagger::TagWriter
- Defined in:
- lib/phtools/exif_tagger/tag_writer.rb
Overview
batch EXIF tags setter
Constant Summary collapse
- DEFAULT_OPTIONS =
%w(-v0 -FileModifyDate<DateTimeOriginal -overwrite_original -ignoreMinorErrors)
Instance Attribute Summary collapse
-
#added_files_count ⇒ Object
readonly
Returns the value of attribute added_files_count.
-
#script_name ⇒ Object
readonly
Returns the value of attribute script_name.
Instance Method Summary collapse
- #add_to_script(phfile: '', tags: {}, options: DEFAULT_OPTIONS) ⇒ Object
- #close_script ⇒ Object
- #command ⇒ Object
-
#initialize(script_name: 'exif_tagger.txt', memo: 'Generated by phtools', output: STDOUT, err: STDERR) ⇒ TagWriter
constructor
A new instance of TagWriter.
- #run! ⇒ Object
Constructor Details
#initialize(script_name: 'exif_tagger.txt', memo: 'Generated by phtools', output: STDOUT, err: STDERR) ⇒ TagWriter
Returns a new instance of TagWriter.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 14 def initialize(script_name: 'exif_tagger.txt', memo: 'Generated by phtools', output: STDOUT, err: STDERR) @script_name = script_name create_script(memo) @added_files_count = 0 @output = output @err = err @output.puts "*** Preparing exiftool script '#{@script_name}' ..." end |
Instance Attribute Details
#added_files_count ⇒ Object (readonly)
Returns the value of attribute added_files_count.
12 13 14 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 12 def added_files_count @added_files_count end |
#script_name ⇒ Object (readonly)
Returns the value of attribute script_name.
12 13 14 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 12 def script_name @script_name end |
Instance Method Details
#add_to_script(phfile: '', tags: {}, options: DEFAULT_OPTIONS) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 25 def add_to_script(phfile: '', tags: {}, options: DEFAULT_OPTIONS) @script.puts "# **(#{@added_files_count + 1})** Processing file: #{phfile} *****" # tags .each do |k| @script.puts .item(k).to_write_script end # file to be altered @script.puts %Q{#{phfile}} # General options .each { |o| @script.puts "#{o}" } @script.puts %Q{-execute} @script.puts @added_files_count += 1 rescue => e raise WriteTag, "adding item to exiftool script - #{e.message}" end |
#close_script ⇒ Object
43 44 45 46 47 48 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 43 def close_script @script.close @output.puts "*** Finished preparation of the script '#{script_name}'" rescue => e raise WriteTag, "closing exiftool script - #{e.message}" end |
#command ⇒ Object
50 51 52 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 50 def command "exiftool -@ #{@script_name}" end |
#run! ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/phtools/exif_tagger/tag_writer.rb', line 54 def run! close_script if @added_files_count > 0 @output.puts "*** Running #{command} ..." ok = system(command, out: @output, err: @err) fail if ok.nil? @output.puts "*** Finished #{command}" else @output.puts "*** Nothing to update, skip running #{command} ..." end rescue raise WriteTag, "running #{command}" end |