Project

spitter

0.0
No commit activity in last 3 years
No release in over 3 years
Takes nice Ruby parameter hashes and spits out whatever crap you need it to.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
~> 2.6
 Project Readme

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¶ ↑

The MIT License

Credit¶ ↑

Spitter is based on @mislav’s nibbler.