Class: Exiftool::Parser

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

Constant Summary collapse

WORD_BOUNDARY_RES =
[/([A-Z\d]+)([A-Z][a-z])/, /([a-z\d])([A-Z])/]
FRACTION_RE =
/^(\d+)\/(\d+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, raw_value) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
17
# File 'lib/exiftool/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/parser.rb', line 10

def display_key
  @display_key
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#raw_valueObject (readonly)

Returns the value of attribute raw_value.



10
11
12
# File 'lib/exiftool/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/parser.rb', line 10

def sym_key
  @sym_key
end

Instance Method Details

#valueObject



19
20
21
22
23
24
25
26
# File 'lib/exiftool/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