Sha256: 15cd6dbbd4aa194f4634c5acd183313e672b45c0f004408d16b27c07707a29f9

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

module Stages
  class Wrap < Stage
    def initialize(pipeline, *args)
      @feeder = Feeder.new
      @pipeline = @feeder | pipeline
      @output_style = :hash
      unless args.empty?
        if args.include? :array
          @output_style = :array
        elsif args.include? :each
          @output_style = :each
        end
        @aggregated = true if args.include? :aggregated
      end
      super()
    end

    def reset
      initialize_loop
      @pipeline.reset
      @source.reset if @source
    end

    def process
      while !source_empty?
        value = input
        @feeder << value
        results = []
        while !@pipeline.done?
          v = @pipeline.run
          @output_style == :each ? output(v) : results << v
        end
        results = results.first if @aggregated
        output results if @output_style == :array
        output({ value => results}) if @output_style == :hash
        @pipeline.reset
      end
      @pipeline.reset
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stages-0.4.1 lib/stages/wrap.rb