Sha256: 398498c506f228d9826435de8f0cac07f81d24ab304e347ec483086e421539a2
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
= 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 :a map :b, ->(v) { v.downcase } map :e, :f, ->(v) { v.downcase } map :O, ->(k,v) { [k.downcase, v.downcase] } map [:i, :j, :k] map [:l, :m, :n], ->(v) { v.upcase } # two-way mapping map :c, :d map :g, :h, ->(v) { v.downcase }, ->(v) { v.upcase } map [:P, :Q, :R], ->(k,v) { [k.downcase, v.downcase] } end Mapper.new(a: 2, b: "STRING") For each mapping defined, an instance method is created that returns the mapped value. This can be mapped directly, with a lambda to map the value or key and value, with an explicit key mapping and lambda value mapping (with an optional reverse-value map lambda), with a directly-mapped array, a directly-mapped array with value mapping, or with an array with keys and values mapped with lambdas. Mapper#original_attributes is the original hash passed in Mapper#mapped_attributes is a hash representing the mapped keys and their mapped values == REQUIREMENTS * Ruby 1.9.x == LICENSE MIT
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attribute_cartographer-0.0.5 | README |