Class: FileData::ExifTagReader

Inherits:
Object
  • Object
show all
Defined in:
lib/file_data/formats/exif/exif_tag_reader.rb

Overview

Enumerates the tags in an ExifStream

Constant Summary collapse

NO_NEXT_IFD =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exif_stream, *ifds_to_include) ⇒ ExifTagReader

Returns a new instance of ExifTagReader.



11
12
13
14
# 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

Instance Attribute Details

#ifds_to_includeObject

Returns the value of attribute ifds_to_include.



9
10
11
# File 'lib/file_data/formats/exif/exif_tag_reader.rb', line 9

def ifds_to_include
  @ifds_to_include
end

#streamObject

Returns the value of attribute stream.



9
10
11
# File 'lib/file_data/formats/exif/exif_tag_reader.rb', line 9

def stream
  @stream
end

Instance Method Details

#ifd_from_offset(ifd_offset, index) ⇒ Object



41
42
43
44
# 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) ⇒ Object



36
37
38
39
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# 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

#tagsObject



16
17
18
19
20
21
22
23
# 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