banzai 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in banzai.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'bundler'
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ end
@@ -0,0 +1,76 @@
1
+ # Banzai
2
+
3
+ Simple toolkit for processing input using filter/pipeline concept.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'banzai'
10
+
11
+ ## Usage
12
+
13
+ First, implement some filters:
14
+
15
+ ```ruby
16
+ class GaussianBlur < Banzai::Filter
17
+ def apply(input)
18
+ # ... filter implementation ...
19
+ end
20
+ end
21
+
22
+ class Nostalgia < Banzai::Filter
23
+ def apply(input)
24
+ # ... filter implementation ...
25
+ end
26
+ end
27
+ ```
28
+
29
+ Then you can apply them to some input
30
+
31
+ ```ruby
32
+ # same as GaussianBlur.new.apply(image)
33
+ GaussianBlur.apply(image)
34
+
35
+ # if you need to pass same filter options
36
+ GaussianBlur.new(radius:1.1).apply(image)
37
+ ```
38
+
39
+ Or if you want to apply multiple filter to an image create pipeline:
40
+
41
+ ```ruby
42
+ # note that you can combine classes and instances
43
+ blurred_effect = Banzai::Pipeline.new [GaussianBlur.new(radius:1.1), Nostalgia]
44
+ blurred_effect.apply(image)
45
+ ```
46
+
47
+ Pipeline is just another filter, so you can mix them too into a new
48
+ pipeline:
49
+ ```ruby
50
+ Banzai::Pipeline.new [blurred_effect, RoundCorners.new(radius:0.87)]
51
+ ```
52
+
53
+ ## Licence
54
+
55
+ Copyright (c) 2012 Dejan Simic
56
+
57
+ MIT License
58
+
59
+ Permission is hereby granted, free of charge, to any person obtaining
60
+ a copy of this software and associated documentation files (the
61
+ "Software"), to deal in the Software without restriction, including
62
+ without limitation the rights to use, copy, modify, merge, publish,
63
+ distribute, sublicense, and/or sell copies of the Software, and to
64
+ permit persons to whom the Software is furnished to do so, subject to
65
+ the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be
68
+ included in all copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
73
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
74
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
75
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
76
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
12
+
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'banzai/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "banzai"
8
+ gem.version = Banzai::VERSION
9
+ gem.authors = ["Dejan Simic"]
10
+ gem.email = ["desimic@gmail.com"]
11
+ gem.description = %q{Simple toolkit for processing input using filter/pipeline concept}
12
+ gem.summary = %q{Simple toolkit for processing input using filter/pipeline concept}
13
+ gem.homepage = "https://github.com/dejan/banzai"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,5 @@
1
+ module Banzai
2
+ autoload :Version, 'banzai/version'
3
+ autoload :Filter, 'banzai/filter'
4
+ autoload :Pipeline, 'banzai/pipeline'
5
+ end
@@ -0,0 +1,20 @@
1
+ module Banzai
2
+ class Filter
3
+
4
+ attr_reader :options
5
+
6
+ def initialize(options={})
7
+ @options = options
8
+ end
9
+
10
+ # should be redefined in subclass
11
+ def apply(input)
12
+ raise NotImplementedError
13
+ end
14
+
15
+ def self.apply(input)
16
+ new.apply(input)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module Banzai
2
+ class Pipeline < Filter
3
+
4
+ def initialize(filters=[])
5
+ @filters = filters
6
+ end
7
+
8
+ def apply(input)
9
+ @filters.inject(input) do |content, filter|
10
+ filter.apply(content)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Banzai
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class LeetFilter < Banzai::Filter
4
+ def apply(input)
5
+ input.gsub(/elite/, '1337')
6
+ end
7
+ end
8
+
9
+ describe Banzai::Filter do
10
+ describe 'subclass' do
11
+ it 'can be created with some options' do
12
+ filter = LeetFilter.new(:mode => 'hardcore')
13
+ assert 'hardcore', filter.options[:mode]
14
+ end
15
+
16
+ it 'applies to some input' do
17
+ assert_equal '1337 security', LeetFilter.apply('elite security')
18
+ assert_equal '1337 security', LeetFilter.new.apply('elite security')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class StripFilter < Banzai::Filter
4
+ def apply(input)
5
+ input.strip
6
+ end
7
+ end
8
+
9
+ class UpcaseFilter < Banzai::Filter
10
+ def apply(input)
11
+ input.upcase
12
+ end
13
+ end
14
+
15
+ describe Banzai::Pipeline do
16
+ it 'applies to input' do
17
+ pipeline = Banzai::Pipeline.new [StripFilter, UpcaseFilter]
18
+ assert_equal 'OHAI', pipeline.apply(' ohai ')
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'banzai'
4
+ require 'minitest/autorun'
5
+
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banzai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dejan Simic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple toolkit for processing input using filter/pipeline concept
15
+ email:
16
+ - desimic@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - banzai.gemspec
26
+ - lib/banzai.rb
27
+ - lib/banzai/filter.rb
28
+ - lib/banzai/pipeline.rb
29
+ - lib/banzai/version.rb
30
+ - test/banzai/filter_test.rb
31
+ - test/banzai/pipeline_test.rb
32
+ - test/test_helper.rb
33
+ homepage: https://github.com/dejan/banzai
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Simple toolkit for processing input using filter/pipeline concept
57
+ test_files:
58
+ - test/banzai/filter_test.rb
59
+ - test/banzai/pipeline_test.rb
60
+ - test/test_helper.rb
61
+ has_rdoc: