Last active
October 13, 2015 13:21
-
-
Save dmichael/1fb1f657e05acc710f25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
require 'active_support/time' | |
require 'money' | |
require 'hashie' | |
class Translator < Hashie::Dash | |
include Hashie::Extensions::IgnoreUndeclared | |
include Hashie::Extensions::Dash::PropertyTranslation | |
include Hashie::Extensions::Coercion | |
end | |
class OrderItemTranslator < Translator | |
property :amount, from: 'amount', with: -> (value) { Money.new(value * 100) } | |
property :quantity, from: 'quantity' | |
end | |
class OrderTranslator < Translator | |
property :created_at, from: 'createddate', with: -> (value) { Time.parse(value) } | |
property :terms, from: 'terms', with: -> (value) { value['name'] } | |
property :subtotal, from: 'subtotal', with: -> (value) { Money.new(value * 100) } | |
property :items, from: 'item' | |
coerce_key :items, Array[OrderItemTranslator] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment