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.



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

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



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

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.



483
484
485
# File 'lib/exifr/tiff.rb', line 483

def fields
  @fields
end

#offsetObject (readonly)

Returns the value of attribute offset.



483
484
485
# File 'lib/exifr/tiff.rb', line 483

def offset
  @offset
end

#typeObject (readonly)

Returns the value of attribute type.



483
484
485
# File 'lib/exifr/tiff.rb', line 483

def type
  @type
end

Instance Method Details

#encode_with(coder) ⇒ Object



537
538
539
# File 'lib/exifr/tiff.rb', line 537

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

#heightObject



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

def height; image_length; end

#inspectObject



525
526
527
# File 'lib/exifr/tiff.rb', line 525

def inspect
  to_hash.inspect
end

#nextObject



533
534
535
# File 'lib/exifr/tiff.rb', line 533

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

#next?Boolean

Returns:

  • (Boolean)


529
530
531
# File 'lib/exifr/tiff.rb', line 529

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

#to_hashObject



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

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



541
542
543
# File 'lib/exifr/tiff.rb', line 541

def to_yaml_properties
  ['@fields']
end

#widthObject



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

def width; image_width; end