Sha256: 7eaf3a13d054a53d95914a95a3b9a1e51f021f9e11d69c454aafed64ef2870fe
Contents?: true
Size: 711 Bytes
Versions: 1
Compression:
Stored size: 711 Bytes
Contents
module Separatum module Converters class Object2Hash def initialize(**params) @common_fields = params[:common_fields] || {} end def call(*objects) objects.flatten.map do |object| hash = if object.respond_to?(:as_json) object.as_json elsif object.respond_to?(:to_hash) object.to_hash elsif object.respond_to?(:to_h) object.to_h else fail end klass = object.class.respond_to?(:name) ? object.class.name : object.class.to_s hash.symbolize_keys.merge(_klass: klass).merge(@common_fields) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
separatum-0.1.1 | lib/separatum/converters/object2_hash.rb |