Module: Cure::Helpers::ObjectHelpers

Included in:
Transformation::Candidate, Transformation::Translation
Defined in:
lib/cure/helpers/object_helpers.rb

Instance Method Summary collapse

Instance Method Details

#attributes=(hash) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/cure/helpers/object_helpers.rb', line 9

def attributes=(hash)
  hash.each do |key, value|
    send("#{key}=", value)
  rescue NoMethodError
    Cure.logger.warn("Error deserializing object: No property for #{key}")
  end
end

#from_hash(hash) ⇒ Object



23
24
25
26
# File 'lib/cure/helpers/object_helpers.rb', line 23

def from_hash(hash)
  self.attributes = hash
  self
end

#from_json(json) ⇒ Object



17
18
19
20
21
# File 'lib/cure/helpers/object_helpers.rb', line 17

def from_json(json)
  return from_hash(json) if json.is_a?(Hash) # Just a guard in case serialisation is done

  from_hash(JSON.parse(json))
end