class FileData::ExifTagReader

Enumerates the tags in an ExifStream

Constants

NO_NEXT_IFD

Attributes

ifds_to_include[RW]
stream[RW]

Public Class Methods

new(exif_stream, *ifds_to_include) click to toggle source
# File lib/file_data/formats/exif/exif_tag_reader.rb, line 11
def initialize(exif_stream, *ifds_to_include)
  @stream = exif_stream
  @ifds_to_include = ifds_to_include
end

Public Instance Methods

ifd_from_offset(ifd_offset, index) click to toggle source
# File lib/file_data/formats/exif/exif_tag_reader.rb, line 41
def ifd_from_offset(ifd_offset, index)
  stream.seek_exif(ifd_offset)
  OrdinalIfd.new(stream, index)
end
next_ifd(index) click to toggle source
# File lib/file_data/formats/exif/exif_tag_reader.rb, line 36
def next_ifd(index)
  ifd_offset = stream.read_value(4)
  ifd_from_offset(ifd_offset, index) unless ifd_offset == NO_NEXT_IFD
end
process_ifd(ifd, enumerator) click to toggle source
# File lib/file_data/formats/exif/exif_tag_reader.rb, line 25
def process_ifd(ifd, enumerator)
  # Yield the tags or just skip ahead

  if ifds_to_include.include?(ifd.index)
    ifd.tags.each { |t| enumerator.yield t }
  else
    # Avoid skipping the last ifd as this is needless work
    ifd.skip unless ifd.index == 1
  end
end
tags() click to toggle source
# File lib/file_data/formats/exif/exif_tag_reader.rb, line 16
def tags
  Enumerator.new do |e|
    2.times do |index|
      break if (ifd = next_ifd(index)).nil?
      process_ifd(ifd, e)
    end
  end
end