class MultiExiftool::Values
Representing (tag, value) pairs of metadata. Access via bracket-methods or dynamic method-interpreting via method_missing.
Constants
- REGEXP_RATIONAL
Regular expression to determine rational values
- REGEXP_TIMESTAMP
Regular expression to determine timestamp values
Attributes
tag_map[R]
Public Class Methods
new(values)
click to toggle source
# File lib/multi_exiftool/values.rb, line 22 def initialize values @values = {} values.map do |tag,val| unified_tag = Values.unify_tag(tag) Values.tag_map[unified_tag] = tag val = val.kind_of?(Hash) ? Values.new(val) : val @values[unified_tag] = val end end
unify_tag(tag)
click to toggle source
# File lib/multi_exiftool/values.rb, line 101 def unify_tag tag tag.gsub(/[-_]/, '').downcase end
Public Instance Methods
[](tag)
click to toggle source
Gets the (posible converted) value for a tag (tag will be unified, i.e. FNumber, fnumber or f_number can be used for FNumber)
# File lib/multi_exiftool/values.rb, line 35 def [](tag) unified_tag = Values.unify_tag(tag) convert(unified_tag, @values[unified_tag]) end
convert(tag, val)
click to toggle source
Converts values on the basis of unified tag name and value. It is called each time a value is fethed from a Values
instance. @return (maybe) converted value
# File lib/multi_exiftool/values.rb, line 43 def convert tag, val return val unless val.kind_of?(String) case tag when 'partofset', 'track' return val end case val when REGEXP_TIMESTAMP year, month, day, hour, minute = $~.captures[0,5].map {|cap| cap.to_i} if month == 0 || day == 0 return nil end second = $6.to_f zone = $7 zone = '+00:00' if zone == 'Z' begin Time.new(year, month, day, hour, minute, second, zone) rescue ArgumentError val end when REGEXP_RATIONAL return val if $2.to_i == 0 Rational($1, $2) else val end end
has_tag?(tag)
click to toggle source
Checks if a tag is present @param Tag as string or symbol (will be unified)
# File lib/multi_exiftool/values.rb, line 73 def has_tag? tag @values.has_key?(Values.unify_tag(tag.to_s)) end
to_h()
click to toggle source
Generates a hash representation of this instance with original tag names es keys and converted values as values
# File lib/multi_exiftool/values.rb, line 85 def to_h @values.inject(Hash.new) do |h, a| tag, val = a h[Values.tag_map[tag]] = convert(Values.unify_tag(tag), val) h end end
Also aliased as: to_hash
Private Instance Methods
method_missing(tag, *args) { |res| ... }
click to toggle source
# File lib/multi_exiftool/values.rb, line 107 def method_missing tag, *args, &block res = self[Values.unify_tag(tag.to_s)] if res && block_given? if block.arity > 0 yield res else res.instance_eval &block end end res end
respond_to_missing?(tag, *args)
click to toggle source
Calls superclass method
# File lib/multi_exiftool/values.rb, line 119 def respond_to_missing? tag, *args has_tag?(tag) || super end