Class: TextUtils::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/text_utils/pipe.rb

Instance Method Summary collapse

Constructor Details

#initialize(*processors) ⇒ Pipe

Returns a new instance of Pipe.



2
3
4
5
6
7
8
9
10
11
# File 'lib/text_utils/pipe.rb', line 2

def initialize *processors
  @processor = processors.reverse.inject nil do |next_processor, meta|
    klass, args = if meta.is_a? Array
      [meta[0], meta[1..-1]]
    else
      [meta, []]
    end
    klass.new next_processor, *args
  end
end

Instance Method Details

#call(text) ⇒ Object



13
14
15
# File 'lib/text_utils/pipe.rb', line 13

def call text
  @processor.call text, {}
end