banzai 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +31 -9
- data/lib/banzai/filter.rb +3 -3
- data/lib/banzai/pipeline.rb +2 -2
- data/lib/banzai/version.rb +1 -1
- data/test/banzai/filter_test.rb +3 -3
- data/test/banzai/pipeline_test.rb +3 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -14,42 +14,64 @@ First, implement some filters:
|
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
class GaussianBlur < Banzai::Filter
|
17
|
-
def
|
17
|
+
def call(input)
|
18
18
|
# ... filter implementation ...
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
class Nostalgia < Banzai::Filter
|
23
|
-
def
|
23
|
+
def call(input)
|
24
24
|
# ... filter implementation ...
|
25
25
|
end
|
26
26
|
end
|
27
27
|
```
|
28
28
|
|
29
|
-
Then you can apply them to some input
|
29
|
+
Then you can apply them to some input:
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
|
33
|
-
GaussianBlur.apply(image)
|
32
|
+
GaussianBlur.new(radius:1.1).call(image)
|
34
33
|
|
35
|
-
#
|
36
|
-
|
34
|
+
# You can also use class method *call* if filter doesn't have options,
|
35
|
+
# or you want to apply default ones (defined in implementation itself)
|
36
|
+
GaussianBlur.call(image)
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
Use pipelines to apply multiple fitlers:
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
# note that you can combine classes and instances
|
43
43
|
blurred_effect = Banzai::Pipeline.new [GaussianBlur.new(radius:1.1), Nostalgia]
|
44
|
-
blurred_effect.
|
44
|
+
blurred_effect.call(image)
|
45
45
|
```
|
46
46
|
|
47
47
|
Pipeline is just another filter, so you can mix them too into a new
|
48
48
|
pipeline:
|
49
|
+
|
49
50
|
```ruby
|
50
51
|
Banzai::Pipeline.new [blurred_effect, RoundCorners.new(radius:0.87)]
|
51
52
|
```
|
52
53
|
|
54
|
+
## Working Example
|
55
|
+
|
56
|
+
Here's a simple working example:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class StripFilter < Banzai::Filter
|
60
|
+
def call(input)
|
61
|
+
input.strip
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class UpcaseFilter < Banzai::Filter
|
66
|
+
def call(input)
|
67
|
+
input.upcase
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
pipeline = Banzai::Pipeline.new [StripFilter, UpcaseFilter]
|
72
|
+
puts pipeline.call(' ohai ') # prints "OHAI"
|
73
|
+
```
|
74
|
+
|
53
75
|
## Licence
|
54
76
|
|
55
77
|
Copyright (c) 2012 Dejan Simic
|
data/lib/banzai/filter.rb
CHANGED
data/lib/banzai/pipeline.rb
CHANGED
data/lib/banzai/version.rb
CHANGED
data/test/banzai/filter_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class LeetFilter < Banzai::Filter
|
4
|
-
def
|
4
|
+
def call(input)
|
5
5
|
input.gsub(/elite/, '1337')
|
6
6
|
end
|
7
7
|
end
|
@@ -14,8 +14,8 @@ describe Banzai::Filter do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'applies to some input' do
|
17
|
-
assert_equal '1337 security', LeetFilter.
|
18
|
-
assert_equal '1337 security', LeetFilter.new.
|
17
|
+
assert_equal '1337 security', LeetFilter.call('elite security')
|
18
|
+
assert_equal '1337 security', LeetFilter.new.call('elite security')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class StripFilter < Banzai::Filter
|
4
|
-
def
|
4
|
+
def call(input)
|
5
5
|
input.strip
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
class UpcaseFilter < Banzai::Filter
|
10
|
-
def
|
10
|
+
def call(input)
|
11
11
|
input.upcase
|
12
12
|
end
|
13
13
|
end
|
@@ -15,6 +15,6 @@ end
|
|
15
15
|
describe Banzai::Pipeline do
|
16
16
|
it 'applies to input' do
|
17
17
|
pipeline = Banzai::Pipeline.new [StripFilter, UpcaseFilter]
|
18
|
-
assert_equal 'OHAI', pipeline.
|
18
|
+
assert_equal 'OHAI', pipeline.call(' ohai ')
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banzai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple toolkit for processing input using filter/pipeline concept
|
15
15
|
email:
|