class Arbor::Model::Serialiser
Public Class Methods
load(data)
click to toggle source
# File lib/arbor/model/serialiser.rb, line 7 def load(data) attributes = parse_attributes(data) resource = data["entityType"].underscore.to_sym Factory.create(resource).new(attributes) end
parse_attributes(attributes)
click to toggle source
# File lib/arbor/model/serialiser.rb, line 14 def parse_attributes(attributes) attr_array = attributes.map do |key, value| value = case value when Hash parse_resource(value) when Array value.map { |nr| parse_resource(nr) } else value end [key, value] end transform_keys(Hash[attr_array]) end
parse_resource(r)
click to toggle source
# File lib/arbor/model/serialiser.rb, line 30 def parse_resource(r) nested_type = r["entityType"] nested_type ? Arbor.serialisers[nested_type].load(r) : r end
transform_keys(hash)
click to toggle source
# File lib/arbor/model/serialiser.rb, line 35 def transform_keys(hash) Hash[hash.map { |k, v| [k.underscore, v] }] end