Class: EXIFR::TIFF::Data

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

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Data

Returns a new instance of Data.



689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/exifr/tiff.rb', line 689

def initialize(file)
  @io = file.respond_to?(:read) ? file : (@file = File.open(file, 'rb'))
  @buffer = ''
  @pos = 0

  case self[0..1]
  when 'II'; @short, @long, @float, @double = 'v', 'V', 'e', 'E'
  when 'MM'; @short, @long, @float, @double = 'n', 'N', 'g', 'G'
  else
    raise MalformedTIFF, "no byte order information found"
  end
end

Instance Attribute Details

#doubleObject (readonly)

Returns the value of attribute double.



687
688
689
# File 'lib/exifr/tiff.rb', line 687

def double
  @double
end

#fileObject (readonly)

Returns the value of attribute file.



687
688
689
# File 'lib/exifr/tiff.rb', line 687

def file
  @file
end

#floatObject (readonly)

Returns the value of attribute float.



687
688
689
# File 'lib/exifr/tiff.rb', line 687

def float
  @float
end

#longObject (readonly)

Returns the value of attribute long.



687
688
689
# File 'lib/exifr/tiff.rb', line 687

def long
  @long
end

#shortObject (readonly)

Returns the value of attribute short.



687
688
689
# File 'lib/exifr/tiff.rb', line 687

def short
  @short
end

Class Method Details

.open(file, &block) ⇒ Object



702
703
704
705
706
707
# File 'lib/exifr/tiff.rb', line 702

def self.open(file, &block)
  data = new(file)
  yield data
ensure
  data && data.file && data.file.close
end

Instance Method Details

#[](pos) ⇒ Object



709
710
711
712
713
714
715
716
717
718
719
# File 'lib/exifr/tiff.rb', line 709

def [](pos)
  unless pos.respond_to?(:begin) && pos.respond_to?(:end)
    pos = pos..pos
  end

  if pos.begin < @pos || pos.end >= @pos + @buffer.size
    read_for(pos)
  end

  @buffer && @buffer[(pos.begin - @pos)..(pos.end - @pos)]
end

#readlong(pos) ⇒ Object



725
726
727
# File 'lib/exifr/tiff.rb', line 725

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

#readshort(pos) ⇒ Object



721
722
723
# File 'lib/exifr/tiff.rb', line 721

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

#sizeObject



729
730
731
732
# File 'lib/exifr/tiff.rb', line 729

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