Class: Exiftool::FieldParser

Inherits:
Object
  • Object
show all
Defined in:
lib/exiftool/field_parser.rb

Constant Summary collapse

WORD_BOUNDARY_RES =
[/([A-Z\d]+)([A-Z][a-z])/, /([a-z\d])([A-Z])/]
FRACTION_RE =
/^(\d+)\/(\d+)$/
YMD_RE =
/\A(\d{4}):(\d{2}):(\d{2})\b/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, raw_value) ⇒ FieldParser

Returns a new instance of FieldParser.



12
13
14
15
16
17
# File 'lib/exiftool/field_parser.rb', line 12

def initialize(key, raw_value)
  @key = key
  @display_key = WORD_BOUNDARY_RES.inject(key) { |k, regex| k.gsub(regex, '\1 \2') }
  @sym_key = display_key.downcase.gsub(' ', '_').to_sym
  @raw_value = raw_value
end

Instance Attribute Details

#display_keyObject (readonly)

Returns the value of attribute display_key.



10
11
12
# File 'lib/exiftool/field_parser.rb', line 10

def display_key
  @display_key
end

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/exiftool/field_parser.rb', line 10

def key
  @key
end

#raw_valueObject (readonly)

Returns the value of attribute raw_value.



10
11
12
# File 'lib/exiftool/field_parser.rb', line 10

def raw_value
  @raw_value
end

#sym_keyObject (readonly)

Returns the value of attribute sym_key.



10
11
12
# File 'lib/exiftool/field_parser.rb', line 10

def sym_key
  @sym_key
end

Instance Method Details

#civil_dateObject



30
31
32
33
34
35
# File 'lib/exiftool/field_parser.rb', line 30

def civil_date
  if datish?
    ymd = raw_value.scan(YMD_RE).first
    Date.civil(*ymd.map{|ea|ea.to_i}) if ymd
  end
end

#valueObject



19
20
21
22
23
24
25
26
# File 'lib/exiftool/field_parser.rb', line 19

def value
  for_lat_long ||
    for_date ||
    for_fraction ||
    raw_value
rescue StandardError => e
  "Warning: Parsing '#{raw_value}' for attribute '#{key}' raised #{e.message}"
end