lib/moneta/api/key_value_serializer.rb in moneta-api-1.1.0 vs lib/moneta/api/key_value_serializer.rb in moneta-api-1.2.0
- old
+ new
@@ -1,16 +1,24 @@
module Moneta
module Api
class KeyValueSerializer
- def self.serialize(entity)
- attributes = entity.properties
+ class << self
+ def serialize(entity)
+ attributes = entity.properties
- attributes.collect do |property, _|
- value = entity.public_send(property)
- key = property.to_s.swapcase
+ attributes.collect do |property, _|
+ value = entity.public_send(property)
+ key = property.to_s.swapcase
- { 'key' => key, 'value' => value } unless value.nil?
- end.compact
+ { 'key' => key, 'value' => value } unless value.nil?
+ end.compact
+ end
+
+ def deserialize(attributes)
+ attributes.each_with_object({}) do |attribute, hash|
+ hash[attribute[:key].to_sym] = attribute.tap { |a| a.delete(:key) }
+ end
+ end
end
end
end
end