Class: EXIFR::TIFF::Data
- Inherits:
-
Object
- Object
- EXIFR::TIFF::Data
- Defined in:
- lib/tiff.rb
Instance Attribute Summary collapse
-
#long ⇒ Object
readonly
Returns the value of attribute long.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
Instance Method Summary collapse
- #[](pos) ⇒ Object
- #endianess=(endianess) ⇒ 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.
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
#long ⇒ Object (readonly)
Returns the value of attribute long.
498 499 500 |
# File 'lib/tiff.rb', line 498 def long @long end |
#short ⇒ Object (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 |
#size ⇒ Object
537 538 539 540 |
# File 'lib/tiff.rb', line 537 def size @file.seek(0, IO::SEEK_END) return @file.pos end |