Spitter <img src=“https://secure.travis-ci.org/bonsaiben/spitter.png”> <img src=“https://gemnasium.com/bonsaiben/spitter.png”>¶ ↑
Takes nice Ruby parameter hashes and spits out whatever crap you need it to. A simple way to provide a custom Ruby interface for the request side of an API wrapper. Based on @mislav’s nibbler.
Installation¶ ↑
gem install spitter
Example Usage¶ ↑
Transform Key¶ ↑
class ApiClient < Spitter parameter :ruby_param => 'apiCamelCaseDataFlag' end $ ApiClient.parse(:ruby_param => '1') => {'apiCamelCaseDataFlag' => '1'}
Transform Value with Lambda¶ ↑
class ApiClient < Spitter parameter :ruby_param => 'apiCamelCaseDataFlag', :with => lambda {|v| v ? '1' : '0'} end $ ApiClient.parse(:ruby_param => true) => {'apiCamelCaseDataFlag' => '1'}
Transform Value with Class¶ ↑
class ApiClient < Spitter class TrueOrFalse def self.parse(val) val ? '1' : '0' end end parameter :ruby_param => 'apiCamelCaseDataFlag', :with => TrueOrFalse end $ ApiClient.parse(:ruby_param => true) => {'apiCamelCaseDataFlag' => '1'}
Transform Value Only¶ ↑
class ApiClient < Spitter parameter :timestamp, :with => lambda{|v| v.to_i.to_s } end $ ApiClient.parse(:timestamp => Time.now) => {'timestamp' => '1341162393'}
License¶ ↑
Credit¶ ↑
Spitter is based on @mislav’s nibbler.