Class: EXIFR::TIFF::Data

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Data

Returns a new instance of Data.



500
501
502
503
504
505
# File 'lib/tiff.rb', line 500

def initialize(file)
  @file = file.respond_to?(:read) ? file : File.open(file, "rb")
  @buff = []
  @pos = 0
  @size = 0
end

Instance Attribute Details

#longObject (readonly)

Returns the value of attribute long.



498
499
500
# File 'lib/tiff.rb', line 498

def long
  @long
end

#shortObject (readonly)

Returns the value of attribute short.



498
499
500
# File 'lib/tiff.rb', line 498

def short
  @short
end

Instance Method Details

#[](pos) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/tiff.rb', line 512

def [](pos)
  # handle Ranges
  if (pos.respond_to?(:min) and pos.respond_to?(:max))
    min = pos.min
    max = pos.max
  else
    min = pos
    max = pos
  end

  if (min < @pos or max >= @pos + @size)
    buff_read(min, max - min)
  end

  return @buffer[(min - @pos)..(max - @pos)]
end

#endianess=(endianess) ⇒ Object



507
508
509
510
# File 'lib/tiff.rb', line 507

def endianess=(endianess)
  @short = endianess.downcase
  @long = endianess.upcase
end

#readlong(pos) ⇒ Object



533
534
535
# File 'lib/tiff.rb', line 533

def readlong(pos)
  self[pos..(pos + 3)].unpack(@long)[0]
end

#readshort(pos) ⇒ Object



529
530
531
# File 'lib/tiff.rb', line 529

def readshort(pos)
  self[pos..(pos + 1)].unpack(@short)[0]
end

#sizeObject



537
538
539
540
# File 'lib/tiff.rb', line 537

def size
  @file.seek(0, IO::SEEK_END)
  return @file.pos
end