Sha256: a93f6d1213ae58e72bb94579f0e99fd7ff2daf92c9cb16fd1cdb2542df8fd3b7

Contents?: true

Size: 624 Bytes

Versions: 17

Compression:

Stored size: 624 Bytes

Contents

module Stages
  class Each < Stage
    def initialize(things = nil, &block)
      @things = things unless things.nil?
      @block = block
      super()
    end
        
    def process 
      if @things
        process_things
      else
        process_inputs
      end
    end
    
    def process_inputs
      while v = input
        v = @block.call(v) if @block
        v.each do |v|
          output v
        end
      end
    end
    
    def process_things
      @things = @block.call(@things) if @block
      output nil if @things.nil?
      @things.each do |thing|
        output thing
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
stages-0.3.4 lib/stages/each.rb
stages-0.3.3 lib/stages/each.rb
stages-0.3.2 lib/stages/each.rb
stages-0.3.1 lib/stages/each.rb
stages-0.3.0 lib/stages/each.rb
stages-0.2.10 lib/stages/each.rb
stages-0.2.9 lib/stages/each.rb
stages-0.2.8 lib/stages/each.rb
stages-0.2.7 lib/stages/each.rb
stages-0.2.6 lib/stages/each.rb
stages-0.2.5 lib/stages/each.rb
stages-0.2.4 lib/stages/each.rb
stages-0.2.3 lib/stages/each.rb
stages-0.2.2 lib/stages/each.rb
stages-0.2.1 lib/stages/each.rb
stages-0.2.0 lib/stages/each.rb
stages-0.1.2 lib/stages/each.rb