Class: APDM::Saxo::IPTC
- Inherits:
-
Object
- Object
- APDM::Saxo::IPTC
- Defined in:
- lib/apdm/saxo/iptc.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #delete_metadata ⇒ Object
- #download ⇒ Object
- #duplicate(original) ⇒ Object
-
#initialize(name, path, options = {}) ⇒ IPTC
constructor
A new instance of IPTC.
- #logger ⇒ Object
- #write(data = {}) ⇒ Object
- #write_metadata(data = {}) ⇒ Object
- #write_value(key, value) ⇒ Object
Constructor Details
#initialize(name, path, options = {}) ⇒ IPTC
Returns a new instance of IPTC.
6 7 8 9 10 11 12 |
# File 'lib/apdm/saxo/iptc.rb', line 6 def initialize(name, path, = {}) self.source = [:source] self.name = name self.path = path self.file = "#{path.chomp('/')}/#{name}" duplicate [:file] if [:file] end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
5 6 7 |
# File 'lib/apdm/saxo/iptc.rb', line 5 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/apdm/saxo/iptc.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/apdm/saxo/iptc.rb', line 5 def path @path end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/apdm/saxo/iptc.rb', line 5 def source @source end |
Instance Method Details
#delete_metadata ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/apdm/saxo/iptc.rb', line 41 def logger.info "Deleting metadata on #{file}." command = "exiv2 -d a delete #{file}" Open3.popen3(command) do |stdin, stdout, stderr| if stderr.gets logger.warn "Could not delete metadata: #{stderr.gets}" end end end |
#download ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/apdm/saxo/iptc.rb', line 28 def download logger.info "Downloading #{source}." begin File.open(file, "wb") do |f| o = open(source) r = o.read f.write r end rescue raise $!, "Problem downloading image with file: #{file} and source: #{source}. #{$!}" end end |
#duplicate(original) ⇒ Object
14 15 16 |
# File 'lib/apdm/saxo/iptc.rb', line 14 def duplicate(original) FileUtils.cp(original, file) end |
#write(data = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/apdm/saxo/iptc.rb', line 22 def write(data = {}) download if source (data) end |
#write_metadata(data = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/apdm/saxo/iptc.rb', line 51 def (data = {}) logger.info "Writing metadata to #{file}." write_value('ObjectName', name) data.each do |key, value| write_value(key.to_s.capitalize, value) end end |
#write_value(key, value) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/apdm/saxo/iptc.rb', line 59 def write_value(key, value) command = "exiv2 -M \"set Iptc.Application2.#{key} String #{value}\" #{file}" Open3.popen3(command) do |stdin, stdout, stderr| if stderr.gets logger.warn "Failed to write #{value} to #{key}: #{stderr.gets}" end end end |