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.



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

#fieldsObject (readonly)

Returns the value of attribute fields.



489
490
491
# File 'lib/exifr/tiff.rb', line 489

def fields
  @fields
end

#offsetObject (readonly)

Returns the value of attribute offset.



489
490
491
# File 'lib/exifr/tiff.rb', line 489

def offset
  @offset
end

#raw_fieldsObject (readonly)

Returns the value of attribute raw_fields.



489
490
491
# File 'lib/exifr/tiff.rb', line 489

def raw_fields
  @raw_fields
end

#typeObject (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

#heightObject



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

def height; image_length; end

#inspectObject



531
532
533
# File 'lib/exifr/tiff.rb', line 531

def inspect
  to_hash.inspect
end

#nextObject



539
540
541
# File 'lib/exifr/tiff.rb', line 539

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

#next?Boolean

Returns:

  • (Boolean)


535
536
537
# File 'lib/exifr/tiff.rb', line 535

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

#to_hashObject



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_propertiesObject



547
548
549
# File 'lib/exifr/tiff.rb', line 547

def to_yaml_properties
  ['@fields']
end

#widthObject



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

def width; image_width; end