Is it possible to create objects from multiple keys? For example, assuming I'm working with charges (payments) for a service and I've made a http request and received a hash like so:
"created_at":"2017-05-01 16:31:33 +0800",
I want to convert this into a Charge object with a Money object storing the amount and currency.
I can create the Money struct easily enough:
class Money < Dry::Struct
attribute :amount, Types::Int
attribute :currency, Types::String
I'd like to create a Charge object using something like:
response = http_get("http://...")
charge = Charge.new(response, JSON.parse(response.body))
To do this I am using dry-initializer:
param :response, Types::Object
option :created_at, Types::Json::DateTime
But I don't know how to create an instance of Money from the amount and currency keys. I want to store the response object so that I can interrigate it if necessary (https status codes etc.).