casecommons / attribute-cartographer Goto Github PK
View Code? Open in Web Editor NEWThis project forked from pivotal-casebook/attribute-cartographer
map :Something, :other_thing, ->(v) { v.uppercase }
License: MIT License
This project forked from pivotal-casebook/attribute-cartographer
map :Something, :other_thing, ->(v) { v.uppercase }
License: MIT License
= Attribute Cartographer * http://github.com/krishicks/attribute-cartographer == DESCRIPTION Attribute Cartographer allows you to map an attributes hash into similarly or differently named methods, using an optional lambda to map the values as well. == INSTALL Add attribute-cartographer to your Gemfile gem 'attribute-cartographer' Then run: $ bundle == USAGE class Mapper include AttributeCartographer # one-way mapping map "UnchangedKey" # map a single key, value untouched map %w{ UnchangedKey1 UnchangedKey2 } # same as above, but for multiple in a single statement map "SameKeyNewValue", ->(v) { v.downcase } # maps the key, using the lambda for the value map %w{ SameKeyNewValue1 SameKeyNewValue2 }, ->(v) { v.upcase } # same as above, but for multiple in a single statement map "OldKey", "new_key", ->(v) { v.downcase } # maps the left key to the right key, using the lambda for the value map "DowncasedKeyAndValue", ->(k,v) { [k.downcase, v.downcase] } # maps the key and value using the lambda for both map %w{ NewKeyAndValue1 NewKeyAndValue2 }, ->(k,v) { [k.downcase, v.downcase] } # same as the example above, but for multiple in a single statement # two-way mapping map "AnotherOldKey", "another_new_key" # map the left key to the right key and vice-versa, value untouched map "ThisKey", "to_this_key", ->(v) { v.downcase }, ->(v) { v.upcase } # map the left key to the right key with the first lambda, # and the right key to the left key with the second lambda end Mapper.new("UnchangedKey" => "UnchangedValue", "OldKey" => "OldValue") # etc. For each mapping defined, an entry in mapped_attributes will be made using the logic defined in the mapping. You also get another method, original_attributes, that retains the entire hash that was passed to #initialize, whether the keys were mapped or not. == REQUIREMENTS * Ruby 1.9.x == LICENSE MIT
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.