Class: EXIFR::TIFF::Data
- Inherits:
-
Object
- Object
- EXIFR::TIFF::Data
- Defined in:
- lib/exifr/tiff.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#long ⇒ Object
readonly
Returns the value of attribute long.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
Class Method Summary collapse
Instance Method Summary collapse
- #[](pos) ⇒ Object
-
#initialize(file) ⇒ Data
constructor
A new instance of Data.
- #readlong(pos) ⇒ Object
- #readshort(pos) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(file) ⇒ Data
Returns a new instance of Data.
643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/exifr/tiff.rb', line 643 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 = 'v', 'V' when 'MM'; @short, @long = 'n', 'N' else raise MalformedTIFF, "no byte order information found" end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
641 642 643 |
# File 'lib/exifr/tiff.rb', line 641 def file @file end |
#long ⇒ Object (readonly)
Returns the value of attribute long.
641 642 643 |
# File 'lib/exifr/tiff.rb', line 641 def long @long end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
641 642 643 |
# File 'lib/exifr/tiff.rb', line 641 def short @short end |
Class Method Details
.open(file, &block) ⇒ Object
656 657 658 659 660 661 |
# File 'lib/exifr/tiff.rb', line 656 def self.open(file, &block) data = new(file) yield data ensure data && data.file && data.file.close end |
Instance Method Details
#[](pos) ⇒ Object
663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/exifr/tiff.rb', line 663 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
679 680 681 |
# File 'lib/exifr/tiff.rb', line 679 def readlong(pos) self[pos..(pos + 3)].unpack(@long)[0] end |
#readshort(pos) ⇒ Object
675 676 677 |
# File 'lib/exifr/tiff.rb', line 675 def readshort(pos) self[pos..(pos + 1)].unpack(@short)[0] end |
#size ⇒ Object
683 684 685 686 |
# File 'lib/exifr/tiff.rb', line 683 def size @io.seek(0, IO::SEEK_END) @io.pos end |