Class: ExifTagger::TagCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/phtools/exif_tagger/tag_collection.rb

Overview

EXIF tags collection

Instance Method Summary collapse

Constructor Details

#initialize(init_values = nil) ⇒ TagCollection

Returns a new instance of TagCollection.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 10

def initialize(init_values = nil)
  @collection = []
  return if init_values.nil?
  case
  when init_values.is_a?(Hash)
    init_values.each do |k, v|
      self[k] = v
    end
  when init_values.is_a?(ExifTagger::TagCollection)
    init_values.each do |item|
      self[item.tag_id] = item.value
    end
  end
end

Instance Method Details

#[](tag) ⇒ Object



41
42
43
44
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 41

def [](tag)
  ind = @collection.find_index(tag)
  ind.nil? ? nil : @collection[ind].value
end

#[]=(tag, value) ⇒ Object



35
36
37
38
39
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 35

def []=(tag, value)
  return if value.nil?
  delete(tag)
  @collection << produce_tag(tag, value.dup)
end

#check_for_warnings(original_values: {}) ⇒ Object



67
68
69
70
71
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 67

def check_for_warnings(original_values: {})
  @collection.each do |i|
    i.check_for_warnings(original_values: original_values)
  end
end

#delete(tag) ⇒ Object



51
52
53
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 51

def delete(tag)
  @collection.delete(tag)
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 25

def each(&block)
  @collection.each(&block)
end

#error_messageObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 73

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) ⇒ Object



46
47
48
49
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 46

def item(tag)
  ind = @collection.find_index(tag)
  ind.nil? ? nil : @collection[ind]
end

#to_sObject



29
30
31
32
33
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 29

def to_s
  str = ''
  @collection.each { |i| str << i.to_s }
  str
end

#valid?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 55

def valid?
  ok = true
  @collection.each { |i| ok &&= i.valid? }
  ok
end

#warning_messageObject



84
85
86
87
88
89
90
91
92
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 84

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?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 61

def with_warnings?
  warn = false
  @collection.each { |i| warn ||= i.warnings.empty? }
  warn
end