Class: ExifData

Inherits:
Hash
  • Object
show all
Includes:
RubyLess
Defined in:
lib/exif_data.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ExifData

You can create new ExifData objects with either a json representation (String), a hash of key => value or an array of key,value pairs.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/exif_data.rb', line 29

def initialize(data)
  if data.kind_of?(String)
    replace JSON::parse(data) rescue {}
  elsif data.kind_of?(Hash)
    replace data
  elsif data.kind_of?(Array)
    replace Hash[*data.flatten] rescue {}
  else
    # ignore
  end
end

Class Method Details

.json_create(serialized) ⇒ Object

Deserialization used by Property



8
9
10
11
12
13
14
# File 'lib/exif_data.rb', line 8

def self.json_create(serialized)
  if data = serialized['data']
    ExifData.new(data)
  else
    nil
  end
end

Instance Method Details

#==(other) ⇒ Object

We need this extra rule to avoid ActiveSupport json encoder thinking Hash is the same object as this. This is a temporary fix until ActiveSupport use object_id for :seen.



23
24
25
# File 'lib/exif_data.rb', line 23

def ==(other)
  other.class == self.class && super
end

#to_json(*args) ⇒ Object

Serialization used by Property



17
18
19
# File 'lib/exif_data.rb', line 17

def to_json(*args)
  { 'json_class' => 'ExifData', 'data' => Hash[self.to_a] }.to_json(*args)
end