Sha256: 4e0a79fbaee9f90929860361430ce68c9a3f1c2c15a333ba1bc6641a443ba7f1

Contents?: true

Size: 1.23 KB

Versions: 28

Compression:

Stored size: 1.23 KB

Contents

module Bmg
  module Operator
    class Ungroup
      include Operator::Unary

      def initialize(type, operand, attrs)
        @type = type
        @operand = operand
        @attrs = attrs
      end

    protected

      attr_reader :attrs

    public

      def each(&bl)
        return to_enum unless block_given?
        if type.knows_keys? && type.keys.any?{|k| (k & attrs).empty? }
          operand.each do |tuple|
            _each(tuple, attrs[0], attrs[1..-1], &bl)
          end
        else
          with_dups = []
          operand.each do |tuple|
            _each(tuple, attrs[0], attrs[1..-1]){|t|
              with_dups << t
            }
          end
          with_dups.uniq.each(&bl)
        end
      end

      def _each(tuple, attr, attrs, &bl)
        rva = tuple[attr] || []
        rva.each do |rvt|
          t = tuple.merge(rvt).tap{|t| t.delete(attr) }
          if attrs.empty?
            yield(t)
          else
            _each(t, attrs[0], attrs[1..-1], &bl)
          end
        end
      end

      def to_ast
        [ :ungroup, operand.to_ast, attrs ]
      end

    protected

    protected ### inspect

      def args
        [ attrs ]
      end

    end # class Ungroup
  end # module Operator
end # module Bmg

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bmg-0.23.3 lib/bmg/operator/ungroup.rb
bmg-0.23.2 lib/bmg/operator/ungroup.rb
bmg-0.23.1 lib/bmg/operator/ungroup.rb
bmg-0.23.0 lib/bmg/operator/ungroup.rb
bmg-0.21.5 lib/bmg/operator/ungroup.rb
bmg-0.21.4 lib/bmg/operator/ungroup.rb
bmg-0.20.5 lib/bmg/operator/ungroup.rb
bmg-0.19.3 lib/bmg/operator/ungroup.rb
bmg-0.21.3 lib/bmg/operator/ungroup.rb
bmg-0.21.2 lib/bmg/operator/ungroup.rb
bmg-0.21.0 lib/bmg/operator/ungroup.rb
bmg-0.20.4 lib/bmg/operator/ungroup.rb
bmg-0.20.2 lib/bmg/operator/ungroup.rb
bmg-0.20.1 lib/bmg/operator/ungroup.rb
bmg-0.20.0 lib/bmg/operator/ungroup.rb
bmg-0.19.2 lib/bmg/operator/ungroup.rb
bmg-0.19.1 lib/bmg/operator/ungroup.rb
bmg-0.19.0 lib/bmg/operator/ungroup.rb
bmg-0.18.15 lib/bmg/operator/ungroup.rb
bmg-0.18.14 lib/bmg/operator/ungroup.rb