GithubHelp home page GithubHelp logo

banzai's Introduction

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.

banzai's People

Contributors

dejan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dmitry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.