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.



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/exifr/tiff.rb', line 487

def initialize(data, offset = nil, type = :image)
  @data, @offset, @type, @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



507
508
509
510
# File 'lib/exifr/tiff.rb', line 507

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.



485
486
487
# File 'lib/exifr/tiff.rb', line 485

def fields
  @fields
end

#offsetObject (readonly)

Returns the value of attribute offset.



485
486
487
# File 'lib/exifr/tiff.rb', line 485

def offset
  @offset
end

#typeObject (readonly)

Returns the value of attribute type.



485
486
487
# File 'lib/exifr/tiff.rb', line 485

def type
  @type
end

Instance Method Details

#encode_with(coder) ⇒ Object



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

def encode_with(coder)
  coder["fields"] = @fields
end

#heightObject



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

def height; image_length; end

#inspectObject



527
528
529
# File 'lib/exifr/tiff.rb', line 527

def inspect
  to_hash.inspect
end

#nextObject



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

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

#next?Boolean

Returns:

  • (Boolean)


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

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

#to_hashObject



515
516
517
518
519
520
521
522
523
524
525
# File 'lib/exifr/tiff.rb', line 515

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



543
544
545
# File 'lib/exifr/tiff.rb', line 543

def to_yaml_properties
  ['@fields']
end

#widthObject



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

def width; image_width; end