Sha256: 33ccf4248b7b609d03937c5084f636653996f133f2fe6ba181f0dd5bd5dd1af1

Contents?: true

Size: 584 Bytes

Versions: 5

Compression:

Stored size: 584 Bytes

Contents

module Alf
  module Engine
    #
    # Infers the heading of the iterated relation.
    #
    class InferHeading
      include Cog

      # @return [Enumerable] The operand
      attr_reader :operand

      def initialize(operand, expr = nil, compiler = nil)
        super(expr, compiler)
        @operand = operand
      end

      def _each
        heading = operand.inject(Alf::Heading::EMPTY){|h,t| h + heading(t) }
        yield(heading.to_h)
      end

    private

      def heading(tuple)
        Alf::Heading[Hash[tuple.map{|k,v| [k, v.class]}]]
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/engine/infer_heading.rb
alf-core-0.16.2 lib/alf/engine/infer_heading.rb
alf-core-0.16.1 lib/alf/engine/infer_heading.rb
alf-core-0.16.0 lib/alf/engine/infer_heading.rb
alf-core-0.15.0 lib/alf/engine/infer_heading.rb