Class: Exiftool::FieldParser
- Inherits:
-
Object
- Object
- Exiftool::FieldParser
- Defined in:
- lib/exiftool/field_parser.rb
Overview
Exiftool FiledParser Class
Constant Summary collapse
- WORD_BOUNDARY_RES =
[/([A-Z\d]+)([A-Z][a-z])/, /([a-z\d])([A-Z])/].freeze
- FRACTION_RE =
%r{^(\d+)/(\d+)$}.freeze
- YMD_RE =
/\A(\d{4}):(\d{2}):(\d{2})\b/.freeze
- ZERO_DATE_RE =
/\A[+:0 ]+\z/.freeze
Instance Attribute Summary collapse
-
#display_key ⇒ Object
readonly
Returns the value of attribute display_key.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#raw_value ⇒ Object
readonly
Returns the value of attribute raw_value.
-
#sym_key ⇒ Object
readonly
Returns the value of attribute sym_key.
Instance Method Summary collapse
- #civil_date ⇒ Object
-
#initialize(key, raw_value) ⇒ FieldParser
constructor
A new instance of FieldParser.
- #value ⇒ Object
Constructor Details
#initialize(key, raw_value) ⇒ FieldParser
Returns a new instance of FieldParser.
15 16 17 18 19 20 |
# File 'lib/exiftool/field_parser.rb', line 15 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_key ⇒ Object (readonly)
Returns the value of attribute display_key.
13 14 15 |
# File 'lib/exiftool/field_parser.rb', line 13 def display_key @display_key end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/exiftool/field_parser.rb', line 13 def key @key end |
#raw_value ⇒ Object (readonly)
Returns the value of attribute raw_value.
13 14 15 |
# File 'lib/exiftool/field_parser.rb', line 13 def raw_value @raw_value end |
#sym_key ⇒ Object (readonly)
Returns the value of attribute sym_key.
13 14 15 |
# File 'lib/exiftool/field_parser.rb', line 13 def sym_key @sym_key end |
Instance Method Details
#civil_date ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/exiftool/field_parser.rb', line 38 def civil_date return unless date? && !zero_date? ymd = raw_value.scan(YMD_RE).first return unless ymd ymd_a = ymd.map(&:to_i) Date.civil(*ymd_a) if Date.valid_civil?(*ymd_a) end |
#value ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/exiftool/field_parser.rb', line 22 def value @value ||= if lat_long? as_lat_long elsif date? as_date elsif fraction? as_fraction else raw_value end rescue StandardError => e # :nocov: "Warning: Parsing '#{raw_value}' for attribute '#{key}' raised #{e.}" # :nocov: end |