Class: Exiftool::FieldParser
- Inherits:
-
Object
- Object
- Exiftool::FieldParser
- 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/- ZERO_DATE_RE =
/\A[+:0 ]+\z/
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.
14 15 16 17 18 19 |
# File 'lib/exiftool/field_parser.rb', line 14 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.
12 13 14 |
# File 'lib/exiftool/field_parser.rb', line 12 def display_key @display_key end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/exiftool/field_parser.rb', line 12 def key @key end |
#raw_value ⇒ Object (readonly)
Returns the value of attribute raw_value.
12 13 14 |
# File 'lib/exiftool/field_parser.rb', line 12 def raw_value @raw_value end |
#sym_key ⇒ Object (readonly)
Returns the value of attribute sym_key.
12 13 14 |
# File 'lib/exiftool/field_parser.rb', line 12 def sym_key @sym_key end |
Instance Method Details
#civil_date ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/exiftool/field_parser.rb', line 35 def civil_date if date? && !zero_date? ymd = raw_value.scan(YMD_RE).first if (ymd) then ymd_a = ymd.map { |ea| ea.to_i } Date.civil(*ymd_a) if Date.valid_civil?(*ymd_a) end end end |
#value ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/exiftool/field_parser.rb', line 21 def value @value ||= if lat_long? as_lat_long elsif date? as_date elsif fraction? as_fraction else raw_value end rescue StandardError => e "Warning: Parsing '#{raw_value}' for attribute '#{key}' raised #{e.}" end |