Class: FormatParser::EXIFParser

Inherits:
Object
  • Object
show all
Includes:
IOUtils
Defined in:
lib/parsers/exif_parser.rb

Defined Under Namespace

Classes: IOExt

Constant Summary collapse

ORIENTATIONS =
[
  :top_left,
  :top_right,
  :bottom_right,
  :bottom_left,
  :left_top,
  :right_top,
  :right_bottom,
  :left_bottom
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IOUtils

#safe_read, #safe_skip

Constructor Details

#initialize(io_blob_with_exif_data) ⇒ EXIFParser

Returns a new instance of EXIFParser.



50
51
52
53
54
55
56
# File 'lib/parsers/exif_parser.rb', line 50

def initialize(io_blob_with_exif_data)
  @exif_io = IOExt.new(io_blob_with_exif_data)
  @exif_data = nil
  @orientation = nil
  @height = nil
  @width = nil
end

Instance Attribute Details

#exif_dataObject

Returns the value of attribute exif_data.



37
38
39
# File 'lib/parsers/exif_parser.rb', line 37

def exif_data
  @exif_data
end

#heightObject

Returns the value of attribute height.



37
38
39
# File 'lib/parsers/exif_parser.rb', line 37

def height
  @height
end

#orientationObject

Returns the value of attribute orientation.



37
38
39
# File 'lib/parsers/exif_parser.rb', line 37

def orientation
  @orientation
end

#widthObject

Returns the value of attribute width.



37
38
39
# File 'lib/parsers/exif_parser.rb', line 37

def width
  @width
end

Instance Method Details

#orientation_parser(raw_exif_data) ⇒ Object



68
69
70
71
# File 'lib/parsers/exif_parser.rb', line 68

def orientation_parser(raw_exif_data)
  value = raw_exif_data.orientation.to_i
  @orientation = ORIENTATIONS[value - 1] if valid_orientation?(value)
end

#scan_image_tiffObject



58
59
60
61
62
63
64
65
66
# File 'lib/parsers/exif_parser.rb', line 58

def scan_image_tiff
  raw_exif_data = EXIFR::TIFF.new(@exif_io)
  # For things that we don't yet have a parser for
  # we make the raw exif result available
  @exif_data = raw_exif_data
  @orientation = orientation_parser(raw_exif_data)
  @width = @exif_data.width
  @height = @exif_data.height
end

#valid_orientation?(value) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/parsers/exif_parser.rb', line 73

def valid_orientation?(value)
  (1..ORIENTATIONS.length).include?(value)
end