Class: EXIFR::TIFF::IFD
- Inherits:
-
Object
- Object
- EXIFR::TIFF::IFD
- Defined in:
- lib/exifr/tiff.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#raw_fields ⇒ Object
readonly
Returns the value of attribute raw_fields.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
- #height ⇒ Object
-
#initialize(data, offset = nil, type = :image) ⇒ IFD
constructor
A new instance of IFD.
- #inspect ⇒ Object
- #method_missing(method, *args) ⇒ Object
- #next ⇒ Object
- #next? ⇒ Boolean
- #to_hash ⇒ Object
- #to_yaml_properties ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(data, offset = nil, type = :image) ⇒ IFD
Returns a new instance of IFD.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/exifr/tiff.rb', line 491 def initialize(data, offset = nil, type = :image) @data, @offset, @type, @raw_fields, @fields = data, offset, type, {}, {} pos = offset || @data.readlong(4) num = @data.readshort(pos) if pos && num pos += 2 num.times do add_field(Field.new(@data, pos)) pos += 12 end @offset_next = @data.readlong(pos) end rescue => ex EXIFR.logger.warn("Badly formed IFD: #{ex}") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
511 512 513 514 |
# File 'lib/exifr/tiff.rb', line 511 def method_missing(method, *args) super unless args.empty? && TAGS.include?(method) to_hash[method] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
489 490 491 |
# File 'lib/exifr/tiff.rb', line 489 def fields @fields end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
489 490 491 |
# File 'lib/exifr/tiff.rb', line 489 def offset @offset end |
#raw_fields ⇒ Object (readonly)
Returns the value of attribute raw_fields.
489 490 491 |
# File 'lib/exifr/tiff.rb', line 489 def raw_fields @raw_fields end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
489 490 491 |
# File 'lib/exifr/tiff.rb', line 489 def type @type end |
Instance Method Details
#encode_with(coder) ⇒ Object
543 544 545 |
# File 'lib/exifr/tiff.rb', line 543 def encode_with(coder) coder["fields"] = @fields end |
#height ⇒ Object
517 |
# File 'lib/exifr/tiff.rb', line 517 def height; image_length; end |
#inspect ⇒ Object
531 532 533 |
# File 'lib/exifr/tiff.rb', line 531 def inspect to_hash.inspect end |
#next ⇒ Object
539 540 541 |
# File 'lib/exifr/tiff.rb', line 539 def next IFD.new(@data, @offset_next) if next? end |
#next? ⇒ Boolean
535 536 537 |
# File 'lib/exifr/tiff.rb', line 535 def next? @offset_next && @offset_next > 0 && @offset_next < @data.size end |
#to_hash ⇒ Object
519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/exifr/tiff.rb', line 519 def to_hash @hash ||= @fields.map do |key,value| if value.nil? {} elsif IFD_TAGS.include?(key) value.to_hash else {key => value} end end.inject { |m,v| m.merge(v) } || {} end |
#to_yaml_properties ⇒ Object
547 548 549 |
# File 'lib/exifr/tiff.rb', line 547 def to_yaml_properties ['@fields'] end |
#width ⇒ Object
516 |
# File 'lib/exifr/tiff.rb', line 516 def width; image_width; end |