banzai 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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 apply(input)
17
+ def call(input)
18
18
  # ... filter implementation ...
19
19
  end
20
20
  end
21
21
 
22
22
  class Nostalgia < Banzai::Filter
23
- def apply(input)
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
- # same as GaussianBlur.new.apply(image)
33
- GaussianBlur.apply(image)
32
+ GaussianBlur.new(radius:1.1).call(image)
34
33
 
35
- # if you need to pass same filter options
36
- GaussianBlur.new(radius:1.1).apply(image)
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
- Or if you want to apply multiple filter to an image create pipeline:
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.apply(image)
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
@@ -8,12 +8,12 @@ module Banzai
8
8
  end
9
9
 
10
10
  # should be redefined in subclass
11
- def apply(input)
11
+ def call(input)
12
12
  raise NotImplementedError
13
13
  end
14
14
 
15
- def self.apply(input)
16
- new.apply(input)
15
+ def self.call(input)
16
+ new.call(input)
17
17
  end
18
18
 
19
19
  end
@@ -5,9 +5,9 @@ module Banzai
5
5
  @filters = filters
6
6
  end
7
7
 
8
- def apply(input)
8
+ def call(input)
9
9
  @filters.inject(input) do |content, filter|
10
- filter.apply(content)
10
+ filter.call(content)
11
11
  end
12
12
  end
13
13
 
@@ -1,3 +1,3 @@
1
1
  module Banzai
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class LeetFilter < Banzai::Filter
4
- def apply(input)
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.apply('elite security')
18
- assert_equal '1337 security', LeetFilter.new.apply('elite security')
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 apply(input)
4
+ def call(input)
5
5
  input.strip
6
6
  end
7
7
  end
8
8
 
9
9
  class UpcaseFilter < Banzai::Filter
10
- def apply(input)
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.apply(' ohai ')
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.1
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-11-30 00:00:00.000000000 Z
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: