Class: ExifrAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/piggy-core/exifr_adapter.rb

Overview

This adapter is used as an additional layer between Piggy and EXIFR.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ExifrAdapter

Returns a new instance of ExifrAdapter.



9
10
11
# File 'lib/piggy-core/exifr_adapter.rb', line 9

def initialize(file)
  @exif = load_exif(file)
end

Instance Method Details

#commentObject



17
18
19
20
21
22
23
24
# File 'lib/piggy-core/exifr_adapter.rb', line 17

def comment
  return '' unless @exif
  c = @exif.comment.class == String ? @exif.comment : @exif.comment.to_s
 c = c.gsub(/\0/, '')
 # m = @exif.make.class == String ? @exif.make : @exif.make.to_s
 # m = m.gsub(/\0/, '')
 # return "#{c} Made with #{m}"
end

#date_timeObject



56
57
58
59
# File 'lib/piggy-core/exifr_adapter.rb', line 56

def date_time
  return nil unless exif?
  @exif.date_time_original
end

#exif?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/piggy-core/exifr_adapter.rb', line 13

def exif?
  @exif && @exif.exif?
end

#heightObject



65
66
67
# File 'lib/piggy-core/exifr_adapter.rb', line 65

def height
  exif? ? @exif.height : 0
end

#to_sObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/piggy-core/exifr_adapter.rb', line 26

def to_s
  return 'no exif' unless @exif
  desc = "Properties:\n"
  desc += "\theight: #{@exif.height.to_s}\n"
  desc += "\twidth: #{@exif.width.to_s}\n"
  desc += "\tbits: #{@exif.bits.to_s}\n"
  if @exif.comment.class == String
    desc += "\tcomment: #{comment}\n"
  elsif @exif.comment.class == Array
    desc += "\tcomments: "
    @exif.comment.each { |c|
      desc += "\t\t#{c}\n"
    }
  end
  return desc unless @exif.exif?
  desc += "Exif:\n\t"
  h = @exif.exif.to_hash
  desc += h.keys.collect { |k| "#{k.to_s}: #{h[k].to_s}" }.join("\n\t")
  return desc
end

#view_degreesObject



47
48
49
50
51
52
53
54
# File 'lib/piggy-core/exifr_adapter.rb', line 47

def view_degrees
  return 0 unless exif?
  orientation = @exif.exif[:orientation]
  return 0 if orientation.nil?
  image_mock = ExifrDegreeComuter.new
  orientation.transform_rmagick(image_mock)
  return image_mock.degree
end

#widthObject



61
62
63
# File 'lib/piggy-core/exifr_adapter.rb', line 61

def width
  exif? ? @exif.width : 0
end