Class: EXIFR::TIFF::Field
- Inherits:
-
Object
- Object
- EXIFR::TIFF::Field
- Defined in:
- lib/tiff.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(data, pos) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(data, pos) ⇒ Field
Returns a new instance of Field.
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/tiff.rb', line 459 def initialize(data, pos) @tag, count, @offset = data.readshort(pos), data.readlong(pos + 4), data.readlong(pos + 8) case data.readshort(pos + 2) when 1, 6 # byte, signed byte # TODO handle signed bytes len, pack = count, proc { |d| d } when 2 # ascii len, pack = count, proc { |d| d.strip } when 3, 8 # short, signed short # TODO handle signed len, pack = count * 2, proc { |d| d.unpack(data.short + '*') } when 4, 9 # long, signed long # TODO handle signed len, pack = count * 4, proc { |d| d.unpack(data.long + '*') } when 5, 10 len, pack = count * 8, proc do |d| r = [] d.unpack(data.long + '*').each_with_index do |v,i| i % 2 == 0 ? r << [v] : r.last << v end r.map do |f| if f[1] == 0 # allow NaN and Infinity f[0].to_f.quo(f[1]) else Rational.respond_to?(:reduce) ? Rational.reduce(*f) : f[0].quo(f[1]) end end end end if len && pack start = len > 4 ? @offset : (pos + 8) @value = [pack[data[start..(start + len - 1)]]].flatten end end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
457 458 459 |
# File 'lib/tiff.rb', line 457 def offset @offset end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
457 458 459 |
# File 'lib/tiff.rb', line 457 def tag @tag end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
457 458 459 |
# File 'lib/tiff.rb', line 457 def value @value end |