Transproc 
Functional transformations for Ruby. It's currently used as one of the data mapping backends in Ruby Object Mapper.
Installation
Add this line to your application's Gemfile:
gem 'transproc'
And then execute:
$ bundle
Or install it yourself as:
$ gem install transproc
Usage
require 'transproc/all'
# compose transformation functions
include Transproc::Helper
transformation = t(:map_array, t(:symbolize_keys) >> t(:rename_keys, user_name: :user))
transformation >>= t(:wrap, :address, [:city, :street, :zipcode])
# call the function
transformation.call(
[
{ 'user_name' => 'Jane',
'city' => 'NYC',
'street' => 'Street 1',
'zipcode' => '123' }
]
)
# => [{:user=>"Jane", :address=>{:city=>"NYC", :street=>"Street 1", :zipcode=>"123"}}]
# Define your own transformations easily
Transproc(:to_json, -> v { JSON.dump(v) })
Transproc(:to_json).call([{ name: 'Jane' }])
# => "[{\"name\":\"Jane\"}]"
# ...or create a module with custom transformations
module MyTransformations
extend Transproc::Functions
def load_json(v)
JSON.load(v)
end
end
(Transproc(:load_json) >> Transproc(:symbolize_keys)).call('[{"name":"Jane"}]')
# => [{ :name => "Jane" }]
Credits
This project is inspired by the work of following people:
- Markus Schirp and morpher project
- Josep M. Bach and kleisli project
Contributing
- Fork it ( https://github.com/solnic/transproc/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
