Class: ExifTagger::Tag::Tag

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/phtools/exif_tagger/tags/_tag.rb

Overview

Parent class for all tags

Constant Summary collapse

EXIFTOOL_TAGS =
[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_norm = '') ⇒ Tag

Returns a new instance of Tag.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 17

def initialize(value_norm = '')
  @value = value_norm
  @errors = []
  @value_invalid = []
  @warnings = []
  @write_script_lines = []
  @info = ''
  @force_write = false
  validate
  @value.freeze
  @errors.freeze
  @value_invalid.freeze
  @warnings.freeze
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



14
15
16
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 14

def errors
  @errors
end

#force_writeObject

Returns the value of attribute force_write.



15
16
17
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 15

def force_write
  @force_write
end

#infoObject

Returns the value of attribute info.



15
16
17
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 15

def info
  @info
end

#valueObject (readonly)

Returns the value of attribute value.



14
15
16
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 14

def value
  @value
end

#value_invalidObject (readonly)

Returns the value of attribute value_invalid.



14
15
16
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 14

def value_invalid
  @value_invalid
end

#warningsObject (readonly)

Returns the value of attribute warnings.



14
15
16
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 14

def warnings
  @warnings
end

#write_script_linesObject (readonly)

Returns the value of attribute write_script_lines.



14
15
16
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 14

def write_script_lines
  @write_script_lines
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 40

def <=>(other)
  if other.respond_to? :tag_id
    tag_id <=> other.tag_id
  else
    tag_id <=> other.to_s.to_sym
  end
end

#check_for_warnings(original_values: {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 56

def check_for_warnings(original_values: {})
  @warnings = []
  self.class::EXIFTOOL_TAGS.each do |tag|
    v = original_values[tag]
    unless v.nil?
      case
      when v.kind_of?(String)
        @warnings << "#{tag_name} has original value: #{tag}='#{v}'" unless v.empty?
      when v.kind_of?(Array)
        @warnings << "#{tag_name} has original value: #{tag}=#{v}" unless v.join.empty?
      else
        @warnings << "#{tag_name} has original value: #{tag}=#{v}"
      end
    end
  end
  @warnings.freeze
end

#tag_idObject



32
33
34
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 32

def tag_id
  self.class.to_s.demodulize.underscore.to_sym
end

#tag_nameObject



36
37
38
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 36

def tag_name
  self.class.to_s.demodulize
end

#to_sObject



48
49
50
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 48

def to_s
  "#{tag_id} = #{@value}"
end

#to_write_scriptObject



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

def to_write_script
  str = ''
  generate_write_script_lines
  unless @write_script_lines.empty?
    str << print_info
    str << print_warnings
    str << print_lines
  end
  str
end

#valid?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/phtools/exif_tagger/tags/_tag.rb', line 52

def valid?
  @errors.empty?
end