Transforms hash by defined commands. Here we focus on how to transform given
object, Spine::Mappings
focuses on result and how to retrieve values for it.
To install it, add the gem to your Gemfile:
gem 'spine-transform'
Then run bundle
. If you're not using Bundler, just gem install spine-transform
.
transformations = Spine::Transform.define do
integer :id
copy :name
decimal :price
boolean :is_available
transform :available, flatten: true do
date :from, to: :available_from
date :until, to: :available_until
end
end
transformations.transform(
id: '1',
name: 'Product',
price: '1.0',
is_available: 'true',
available: { from: '2014-01-01', until: '2015-01-01' }
)