Class: Banzai::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/banzai/filter.rb

Overview

Filter transforms an input into desired output. The process of transformation should be implemented in the #call method.

Direct Known Subclasses

Pipeline

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • options (Hash) (defaults to: {})

    The parameters that method #call can utilize to make processing customizable



11
12
13
# File 'lib/banzai/filter.rb', line 11

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/banzai/filter.rb', line 7

def options
  @options
end

Class Method Details

.call(input) ⇒ Object

Delegates to #call by creating an instance with default options

Parameters:

  • input (Object)


28
29
30
# File 'lib/banzai/filter.rb', line 28

def self.call(input)
  new.call(input)
end

Instance Method Details

#call(input) ⇒ Object

Subclass should redefine this method to transform input to desired output. Input and return value should be the same type to provide way of chaining filters

Parameters:

  • input (Object)

Returns:

  • (Object)

    the desired output



21
22
23
# File 'lib/banzai/filter.rb', line 21

def call(input)
  input
end