Sha256: ce6b7878c2f87c952f439bea59e2567a14be153c1b715a6905f71ff7f5101c7c

Contents?: true

Size: 885 Bytes

Versions: 38

Compression:

Stored size: 885 Bytes

Contents

require 'arc-furnace/source'

# Filters limit rows to downstream nodes. They act just like Enumerable#filter:
# when the #filter method returns true, the row is passed downstream. when
# it returns false, the row is skipped.
module ArcFurnace
  class Filter < Source

    private_attr_reader :source

    def initialize(source:)
      @source = source
      @value = nil
    end

    def value
      if @value.nil? && !empty?
        advance
      end
      @value
    end
    # Given a row from the source, tell if it should be passed down to the next
    # node downstream from this node.
    #
    # This method must return a boolean
    def filter(row)
      raise "Unimplemented"
    end

    def empty?
      @value.nil? && source.empty?
    end

    def advance
      loop do
        @value = source.row
        break if value.nil? || filter(value)
      end
    end

  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
arc-furnace-0.1.42 lib/arc-furnace/filter.rb
arc-furnace-0.1.41 lib/arc-furnace/filter.rb
arc-furnace-0.1.40 lib/arc-furnace/filter.rb
arc-furnace-0.1.39 lib/arc-furnace/filter.rb
arc-furnace-0.1.38 lib/arc-furnace/filter.rb
arc-furnace-0.1.37 lib/arc-furnace/filter.rb
arc-furnace-0.1.36 lib/arc-furnace/filter.rb
arc-furnace-0.1.35 lib/arc-furnace/filter.rb
arc-furnace-0.1.34 lib/arc-furnace/filter.rb
arc-furnace-0.1.33 lib/arc-furnace/filter.rb
arc-furnace-0.1.32 lib/arc-furnace/filter.rb
arc-furnace-0.1.31 lib/arc-furnace/filter.rb
arc-furnace-0.1.30 lib/arc-furnace/filter.rb
arc-furnace-0.1.29 lib/arc-furnace/filter.rb
arc-furnace-0.1.28 lib/arc-furnace/filter.rb
arc-furnace-0.1.27 lib/arc-furnace/filter.rb
arc-furnace-0.1.26 lib/arc-furnace/filter.rb
arc-furnace-0.1.25 lib/arc-furnace/filter.rb
arc-furnace-0.1.24 lib/arc-furnace/filter.rb
arc-furnace-0.1.23 lib/arc-furnace/filter.rb