Class: EXIFR::TIFF::IFD

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, offset = nil, type = :image) ⇒ IFD

Returns a new instance of IFD



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/exifr/tiff.rb', line 455

def initialize(data, offset = nil, type = :image)
  @data, @offset, @type, @fields = data, offset, type, {}

  pos = offset || @data.readlong(4)
  num = @data.readshort(pos)
  pos += 2

  num.times do
    add_field(Field.new(@data, pos))
    pos += 12
  end

  @offset_next = @data.readlong(pos)
rescue => ex
  EXIFR.logger.warn("Badly formed IFD: #{ex}")
  @offset_next = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



473
474
475
476
# File 'lib/exifr/tiff.rb', line 473

def method_missing(method, *args)
  super unless args.empty? && TAGS.include?(method.to_s)
  to_hash[method]
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields



453
454
455
# File 'lib/exifr/tiff.rb', line 453

def fields
  @fields
end

#offsetObject (readonly)

Returns the value of attribute offset



453
454
455
# File 'lib/exifr/tiff.rb', line 453

def offset
  @offset
end

#typeObject (readonly)

Returns the value of attribute type



453
454
455
# File 'lib/exifr/tiff.rb', line 453

def type
  @type
end

Instance Method Details

#heightObject



479
# File 'lib/exifr/tiff.rb', line 479

def height; image_length; end

#inspectObject



493
494
495
# File 'lib/exifr/tiff.rb', line 493

def inspect
  to_hash.inspect
end

#nextObject



501
502
503
# File 'lib/exifr/tiff.rb', line 501

def next
  IFD.new(@data, @offset_next) if next?
end

#next?Boolean

Returns:

  • (Boolean)


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

def next?
  @offset_next != 0 && @offset_next < @data.size
end

#to_hashObject



481
482
483
484
485
486
487
488
489
490
491
# File 'lib/exifr/tiff.rb', line 481

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_propertiesObject



505
506
507
# File 'lib/exifr/tiff.rb', line 505

def to_yaml_properties
  ['@fields']
end

#widthObject



478
# File 'lib/exifr/tiff.rb', line 478

def width; image_width; end