Skip to content
A rude little tool that takes nice Ruby parameter hashes and spits out whatever crap you need.
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
README.rdoc
Rakefile
spitter.gemspec

README.rdoc

Spitter

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.

Something went wrong with that request. Please try again.