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
Licence
Banzai is released under the MIT License.