This repository has been archived by the owner. It is now read-only.
Simple toolkit for processing input using pipelines & filters
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Upgrade rubocop & yard Mar 9, 2018
lib Upgrade rubocop & yard Mar 9, 2018
spec Upgrade rubocop & yard Mar 9, 2018
.gitignore Add rubocop Sep 30, 2015
.rspec Replace minitest with rspec Sep 27, 2015
.ruby-version Set ruby version Mar 9, 2018
Gemfile Upgrade rubocop & yard Mar 9, 2018
MIT-LICENCE Fix the year in licence Dec 6, 2015
README.md Readme cleanup Dec 6, 2015
Rakefile Upgrade rubocop & yard Mar 9, 2018
banzai.gemspec Bump version Mar 9, 2018
circle.yml Upgrade circle to new version Mar 9, 2018

README.md

Banzai

Simple toolkit for processing input using filter/pipeline concept.

Installation

Add this line to your application's Gemfile:

gem 'banzai'

Usage

First, implement some filters:

class GaussianBlur < Banzai::Filter
  def call(input)
    # process input
    # ...
  end
end 

class Nostalgia < Banzai::Filter
  def call(input)
    # process input
    # ...
  end
end

Then you can apply them to some input:

GaussianBlur.new(radius:1.1).call(image)

You can also use class method call if filter doesn't have options, or you want to apply default ones (defined in implementation itself):

Nostalgia.call(image)

To apply multiple filters to input use Banzai::Pipeline. Note that you can combine filter class and it's instances:

blurred_effect = Banzai::Pipeline.new(GaussianBlur.new(radius:1.1), Nostalgia)
blurred_effect.call(image)

Banzai::Pipeline is just another filter, so you can mix them with filters into a new pipeline:

Banzai::Pipeline.new(blurred_effect, RoundCorners.new(radius:0.87))

Working Example

Here's a simple working example:

class StripFilter < Banzai::Filter
  def call(input)
    input.strip
  end
end

class UpcaseFilter < Banzai::Filter
  def call(input)
    input.upcase
  end
end

pipeline = Banzai::Pipeline.new(StripFilter, UpcaseFilter)
puts pipeline.call('    ohai ') # prints "OHAI"

Contributing

Open a pull request but first make sure this is green:

bundle exec rake

Code status

Circle CI

Licence

Banzai is released under the MIT License.