class ExifTagger::TagCollection

EXIF tags collection

Public Class Methods

new(init_values = nil) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 13
def initialize(init_values = nil)
  @collection = []
  return if init_values.nil?

  if init_values.is_a?(Hash)
    init_values.each { |k, v| self[k] = v }

  elsif init_values.is_a?(ExifTagger::TagCollection)
    init_values.each { |item| self[item.tag_id] = item.value }

  elsif init_values.is_a?(MiniExiftool)
    TAGS_SUPPORTED.each { |tag| self[tag] = init_values }
  end
end

Public Instance Methods

[](tag) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 44
def [](tag)
  ind = @collection.find_index(tag)
  ind.nil? ? nil : @collection[ind].value
end
[]=(tag, value) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 38
def []=(tag, value)
  return if value.nil?
  delete(tag)
  @collection << produce_tag(tag, value)
end
check_for_warnings(original_values: {}) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 70
def check_for_warnings(original_values: {})
  @collection.each do |i|
    i.check_for_warnings(original_values: original_values)
  end
end
delete(tag) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 54
def delete(tag)
  @collection.delete(tag)
end
each(&block) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 28
def each(&block)
  @collection.each(&block)
end
error_message() click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 76
def error_message
  str = ''
  unless valid?
    str = +"Tags are NOT VALID:\n"
    @collection.each do |item|
      item.errors.each { |e| str << '    ' + e + "\n" }
    end
  end
  str
end
item(tag) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 49
def item(tag)
  ind = @collection.find_index(tag)
  ind.nil? ? nil : @collection[ind]
end
to_s() click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 32
def to_s
  str = +''
  @collection.each { |i| str << i.to_s }
  str
end
valid?() click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 58
def valid?
  ok = true
  @collection.each { |i| ok &&= i.valid? }
  ok
end
warning_message() click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 87
def warning_message
  str = +''
  if with_warnings?
    @collection.each do |item|
      item.warnings.each { |e| str << '    WARNING: ' + e + "\n" }
    end
  end
  str
end
with_warnings?() click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 64
def with_warnings?
  warn = false
  @collection.each { |i| warn ||= i.warnings.empty? }
  warn
end

Private Instance Methods

produce_tag(tag, value) click to toggle source
# File lib/phtools/exif_tagger/tag_collection.rb, line 99
def produce_tag(tag, value)
  tag_class = ExifTagger::Tag.const_get(tag.to_s.camelize)
  tag_class.new(value)
rescue => e
  raise ExifTagger::UnknownTag, "Tag #{tag.to_s.camelize}, value '#{value}' - #{e.message}"
end