Class: EXIFR::TIFF::Field

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#offsetObject (readonly)

Returns the value of attribute offset.



457
458
459
# File 'lib/tiff.rb', line 457

def offset
  @offset
end

#tagObject (readonly)

Returns the value of attribute tag.



457
458
459
# File 'lib/tiff.rb', line 457

def tag
  @tag
end

#valueObject (readonly)

Returns the value of attribute value.



457
458
459
# File 'lib/tiff.rb', line 457

def value
  @value
end