Class: ExifTagger::TagCollection
- Inherits:
-
Object
- Object
- ExifTagger::TagCollection
- Includes:
- Enumerable
- Defined in:
- lib/phtools/exif_tagger/tag_collection.rb
Overview
EXIF tags collection
Instance Method Summary collapse
- #[](tag) ⇒ Object
- #[]=(tag, value) ⇒ Object
- #check_for_warnings(original_values: {}) ⇒ Object
- #delete(tag) ⇒ Object
- #each(&block) ⇒ Object
- #error_message ⇒ Object
-
#initialize(init_values = nil) ⇒ TagCollection
constructor
A new instance of TagCollection.
- #item(tag) ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #warning_message ⇒ Object
- #with_warnings? ⇒ Boolean
Constructor Details
#initialize(init_values = nil) ⇒ TagCollection
Returns a new instance of TagCollection.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Method Details
#[](tag) ⇒ Object
44 45 46 47 |
# 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) ⇒ Object
38 39 40 41 42 |
# 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: {}) ⇒ Object
70 71 72 73 74 |
# 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) ⇒ Object
54 55 56 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 54 def delete(tag) @collection.delete(tag) end |
#each(&block) ⇒ Object
28 29 30 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 28 def each(&block) @collection.each(&block) end |
#error_message ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 76 def 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
49 50 51 52 |
# 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 ⇒ Object
32 33 34 35 36 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 32 def to_s str = +'' @collection.each { |i| str << i.to_s } str end |
#valid? ⇒ Boolean
58 59 60 61 62 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 58 def valid? ok = true @collection.each { |i| ok &&= i.valid? } ok end |
#warning_message ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 87 def str = +'' if with_warnings? @collection.each do |item| item.warnings.each { |e| str << ' WARNING: ' + e + "\n" } end end str end |
#with_warnings? ⇒ Boolean
64 65 66 67 68 |
# File 'lib/phtools/exif_tagger/tag_collection.rb', line 64 def with_warnings? warn = false @collection.each { |i| warn ||= i.warnings.empty? } warn end |