banzai 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87ecd06527099239eda1d67d3200f3c8bd8af7db
4
- data.tar.gz: 1deddcd37be707e8f0672792ba3448c1715f20ae
3
+ metadata.gz: 33df5d09bd02ee144ba10a0b34d13071ba1d3855
4
+ data.tar.gz: ab729868341e7b5145c3f70fdf263099dd079fc1
5
5
  SHA512:
6
- metadata.gz: 8480c04557749e992d7acb89e1d8049638f190679a4305399abce780e05b55da529d3aca33a69fc4504dc078dd697f2811c72616dc1f354af6ea3b539d581a8c
7
- data.tar.gz: 709ea20a481df1a63b6f15bd9a94b62090e199bdc168c1cebadfba4f23699c294f8880db1d5333d787502828b4d4590cbe71d67f7c673d108ed98803e2af959e
6
+ metadata.gz: 864fba492a923a8ff6c24b4ce8e5ea56d8b8b47d8a1b414722ded28d5c20aea51228c975e04071e9f30f81537918f46a6190abc1556949e81a97d9e6b053b552
7
+ data.tar.gz: 34c9122ab610c73c9b91bcc8dcf2454d7f6fb06d7877c3fb0ecf5c6c55ee3dfbaecb4e9e25501a4f496e6056e99f4a849041464bacea12575d62425fe13fdb41
data/README.md CHANGED
@@ -74,6 +74,12 @@ pipeline = Banzai::Pipeline.new(StripFilter, UpcaseFilter)
74
74
  puts pipeline.call(' ohai ') # prints "OHAI"
75
75
  ```
76
76
 
77
+ ## Contributing
78
+
79
+ Open a pull request but first make sure this is green:
80
+
81
+ bundle exec rake
82
+
77
83
 
78
84
  ## Licence
79
85
 
data/lib/banzai.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Banzai is a simple toolkit for processing any input using filters.
2
+ # Multiple filters can be combined into a pipeline that will transform input
3
+ # by appliyng filters in chain feeding next one with the output of the previous.
1
4
  module Banzai
2
5
  autoload :Version, 'banzai/version'
3
6
  autoload :Filter, 'banzai/filter'
data/lib/banzai/filter.rb CHANGED
@@ -1,20 +1,28 @@
1
1
  module Banzai
2
+ # Filter transforms an input into desired output. The process of
3
+ # transformation should be implemented in the {#call} method.
2
4
  class Filter
3
-
4
5
  attr_reader :options
5
6
 
6
- def initialize(options={})
7
+ # @param options [Hash] filter parameters that method {#call} can utilize
8
+ # to make processing customizable
9
+ def initialize(options = {})
7
10
  @options = options
8
11
  end
9
12
 
10
- # This method should be redefined in subclasses
13
+ # Subclass should redefine this method to transform input to desired output
14
+ #
15
+ # @param input [Object] the type of the input is not defined since it will
16
+ # depend on the (re)implementation of the method
11
17
  def call(input)
12
- raise NotImplementedError
18
+ input
13
19
  end
14
20
 
21
+ # Delegates to {#call} by creating an instance with default options
22
+ #
23
+ # @param input [Object]
15
24
  def self.call(input)
16
25
  new.call(input)
17
26
  end
18
-
19
27
  end
20
28
  end
@@ -1,15 +1,15 @@
1
1
  module Banzai
2
+ # Pipeline is a filter that accept an array of filters that will be applied
3
+ # to input sequentially.
2
4
  class Pipeline < Filter
3
-
4
5
  def initialize(*filters)
5
6
  @filters = filters.flatten
6
7
  end
7
-
8
+
8
9
  def call(input)
9
10
  @filters.inject(input) do |content, filter|
10
11
  filter.call(content)
11
12
  end
12
13
  end
13
-
14
14
  end
15
15
  end
data/spec/filter_spec.rb CHANGED
@@ -1,26 +1,27 @@
1
- describe Banzai::Filter, 'subclass' do
2
-
3
- class LeetFilter < Banzai::Filter
1
+ RSpec.describe Banzai::Filter, 'subclass' do
2
+ # A simple Filter implementation for testing
3
+ class Yell < Banzai::Filter
4
4
  def call(input)
5
- input.gsub(/elite/, '1337')
5
+ input.to_s.upcase + '!' * level
6
6
  end
7
- end
8
7
 
9
- context 'instance' do
10
- it 'is created with options' do
11
- filter = LeetFilter.new(:mode => 'hardcore')
12
- expect(filter.options[:mode]).to eq 'hardcore'
8
+ def level
9
+ options[:level] || 1
13
10
  end
11
+ end
14
12
 
15
- it 'applies to input' do
16
- expect(LeetFilter.new.call('elite security')).to eq '1337 security'
13
+ subject { Yell }
14
+ let(:input) { 'chunky bacon' }
15
+
16
+ describe '.call' do
17
+ it 'filters the input' do
18
+ expect(subject.call(input)).to eq 'CHUNKY BACON!'
17
19
  end
18
20
  end
19
21
 
20
- context 'class' do
21
- it 'applies to input' do
22
- expect(LeetFilter.call('elite security')).to eq '1337 security'
22
+ describe '#call' do
23
+ it 'filters the input using options' do
24
+ expect(subject.new(level: 3).call(input)).to eq 'CHUNKY BACON!!!'
23
25
  end
24
26
  end
25
-
26
27
  end
@@ -1,25 +1,36 @@
1
- describe Banzai::Pipeline do
2
-
3
- class StripFilter < Banzai::Filter
1
+ RSpec.describe Banzai::Pipeline do
2
+ # Simple filter implementation for testing
3
+ class Strip < Banzai::Filter
4
4
  def call(input)
5
5
  input.strip
6
6
  end
7
7
  end
8
8
 
9
- class UpcaseFilter < Banzai::Filter
9
+ # Simple filter implementation for testing
10
+ class Upcase < Banzai::Filter
10
11
  def call(input)
11
12
  input.upcase
12
13
  end
13
14
  end
14
15
 
15
- it 'applies provided filters to input' do
16
- pipeline = Banzai::Pipeline.new(StripFilter, UpcaseFilter)
17
- expect(pipeline.call(' ohai ')).to eq 'OHAI'
18
- end
16
+ let(:input) { ' ohai ' }
17
+ let(:output) { 'OHAI' }
19
18
 
20
- it 'accepts array of filters' do
21
- pipeline = Banzai::Pipeline.new([StripFilter, UpcaseFilter])
22
- expect(pipeline.call(' ohai ')).to eq 'OHAI'
19
+ describe 'initialized with array of filters' do
20
+ subject { Banzai::Pipeline.new([Strip, Upcase]) }
21
+ describe '.call' do
22
+ it 'filters the input' do
23
+ expect(subject.call(input)).to eq output
24
+ end
25
+ end
23
26
  end
24
27
 
28
+ describe 'initialized with splatted array of filters' do
29
+ subject { Banzai::Pipeline.new(Strip, Upcase) }
30
+ describe '.call' do
31
+ it 'filters the input' do
32
+ expect(subject.call(input)).to eq output
33
+ end
34
+ end
35
+ end
25
36
  end
data/spec/spec_helper.rb CHANGED
@@ -1,98 +1,11 @@
1
1
  require 'banzai'
2
2
 
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause
6
- # this file to always be loaded, without a need to explicitly require it in any
7
- # files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider making
13
- # a separate helper file that requires the additional dependencies and performs
14
- # the additional setup, and require it from the spec files that actually need
15
- # it.
16
- #
17
- # The `.rspec` file also contains a few flags that are not defaults but that
18
- # users commonly want.
19
- #
20
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
3
  RSpec.configure do |config|
22
- # rspec-expectations config goes here. You can use an alternate
23
- # assertion/expectation library such as wrong or the stdlib/minitest
24
- # assertions if you prefer.
25
4
  config.expect_with :rspec do |expectations|
26
- # This option will default to `true` in RSpec 4. It makes the `description`
27
- # and `failure_message` of custom matchers include text for helper methods
28
- # defined using `chain`, e.g.:
29
- # be_bigger_than(2).and_smaller_than(4).description
30
- # # => "be bigger than 2 and smaller than 4"
31
- # ...rather than:
32
- # # => "be bigger than 2"
33
5
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
6
  end
35
7
 
36
- # rspec-mocks config goes here. You can use an alternate test double
37
- # library (such as bogus or mocha) by changing the `mock_with` option here.
38
8
  config.mock_with :rspec do |mocks|
39
- # Prevents you from mocking or stubbing a method that does not exist on
40
- # a real object. This is generally recommended, and will default to
41
- # `true` in RSpec 4.
42
9
  mocks.verify_partial_doubles = true
43
10
  end
44
-
45
- # The settings below are suggested to provide a good initial experience
46
- # with RSpec, but feel free to customize to your heart's content.
47
- =begin
48
- # These two settings work together to allow you to limit a spec run
49
- # to individual examples or groups you care about by tagging them with
50
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
- # get run.
52
- config.filter_run :focus
53
- config.run_all_when_everything_filtered = true
54
-
55
- # Allows RSpec to persist some state between runs in order to support
56
- # the `--only-failures` and `--next-failure` CLI options. We recommend
57
- # you configure your source control system to ignore this file.
58
- config.example_status_persistence_file_path = "spec/examples.txt"
59
-
60
- # Limits the available syntax to the non-monkey patched syntax that is
61
- # recommended. For more details, see:
62
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
- config.disable_monkey_patching!
66
-
67
- # This setting enables warnings. It's recommended, but in some cases may
68
- # be too noisy due to issues in dependencies.
69
- config.warnings = true
70
-
71
- # Many RSpec users commonly either run the entire suite or an individual
72
- # file, and it's useful to allow more verbose output when running an
73
- # individual spec file.
74
- if config.files_to_run.one?
75
- # Use the documentation formatter for detailed output,
76
- # unless a formatter has already been configured
77
- # (e.g. via a command-line flag).
78
- config.default_formatter = 'doc'
79
- end
80
-
81
- # Print the 10 slowest examples and example groups at the
82
- # end of the spec run, to help surface which specs are running
83
- # particularly slow.
84
- config.profile_examples = 10
85
-
86
- # Run specs in random order to surface order dependencies. If you find an
87
- # order dependency and want to debug it, you can fix the order by providing
88
- # the seed, which is printed after each run.
89
- # --seed 1234
90
- config.order = :random
91
-
92
- # Seed global randomization in this process using the `--seed` CLI option.
93
- # Setting this allows you to use `--seed` to deterministically reproduce
94
- # test failures related to randomization by passing the same `--seed` value
95
- # as the one that triggered the failure.
96
- Kernel.srand config.seed
97
- =end
98
11
  end
metadata CHANGED
@@ -1,37 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banzai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dejan Simic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-27 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Simple toolkit for processing input using filter/pipeline concept
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Toolkit for processing input using filters and pipelines
14
42
  email:
15
43
  - desimic@gmail.com
16
44
  executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
20
- - ".gitignore"
21
- - ".rspec"
22
- - Gemfile
23
48
  - README.md
24
- - Rakefile
25
- - banzai.gemspec
26
49
  - lib/banzai.rb
27
50
  - lib/banzai/filter.rb
28
51
  - lib/banzai/pipeline.rb
29
- - lib/banzai/version.rb
30
52
  - spec/filter_spec.rb
31
53
  - spec/pipeline_spec.rb
32
54
  - spec/spec_helper.rb
33
55
  homepage: https://github.com/dejan/banzai
34
- licenses: []
56
+ licenses:
57
+ - MIT
35
58
  metadata: {}
36
59
  post_install_message:
37
60
  rdoc_options: []
@@ -52,8 +75,9 @@ rubyforge_project:
52
75
  rubygems_version: 2.4.5
53
76
  signing_key:
54
77
  specification_version: 4
55
- summary: Simple toolkit for processing input using filter/pipeline concept
78
+ summary: Toolkit for processing input using filters and pipelines
56
79
  test_files:
57
80
  - spec/filter_spec.rb
58
81
  - spec/pipeline_spec.rb
59
82
  - spec/spec_helper.rb
83
+ has_rdoc:
data/.gitignore DELETED
@@ -1,17 +0,0 @@
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/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/Gemfile DELETED
@@ -1,10 +0,0 @@
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 'rspec'
10
- end
data/Rakefile DELETED
@@ -1,12 +0,0 @@
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
-
data/banzai.gemspec DELETED
@@ -1,19 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- module Banzai
2
- VERSION = "0.1.1"
3
- end