Sha256: a6b4503d9d5906bb0c056ae911cdfd9fd86c071b4a0628d295bca6d4145f1455
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 map :a map :b, ->(v) { v.downcase } map :O, ->(k,v) { [k.downcase, v.downcase] } # You must return a 2-arg array map :c, :d map :e, :f, ->(v) { v.downcase } map :g, :h, ->(v) { v.downcase }, ->(v) { v.upcase } map [:i, :j, :k] map [:l, :m, :n], ->(v) { v.upcase } map [:P, :Q, :R], ->(k,v) { [k.downcase, v.downcase] } # You must return a 2-arg array 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.4 | README |