Class: ExifData
Class Method Summary collapse
-
.json_create(serialized) ⇒ Object
Deserialization used by Property.
Instance Method Summary collapse
-
#==(other) ⇒ Object
We need this extra rule to avoid ActiveSupport json encoder thinking Hash is the same object as this.
-
#initialize(data) ⇒ ExifData
constructor
You can create new ExifData objects with either a json representation (String), a hash of key => value or an array of key,value pairs.
-
#to_json(*args) ⇒ Object
Serialization used by Property.
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
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 |