class Bmg::Operator::Group
Group
operator.
Groups some operand attributes as a new Relation-valued attribute
Constants
- DEFAULT_OPTIONS
Attributes
as[R]
attrs[R]
options[R]
Public Class Methods
new(type, operand, attrs, as, options)
click to toggle source
# File lib/bmg/operator/group.rb, line 20 def initialize(type, operand, attrs, as, options) @type = type @operand = operand @attrs = attrs @as = as @options = DEFAULT_OPTIONS.merge(options) end
Public Instance Methods
each() { |tuple| ... }
click to toggle source
# File lib/bmg/operator/group.rb, line 34 def each(&bl) return to_enum unless block_given? index = Hash.new{|h,k| h[k] = k.merge(as => empty_group) } operand.each do |tuple| key = TupleAlgebra.allbut(tuple, attrs) sub = TupleAlgebra.project(tuple, attrs) index[key][as].operand << sub end if options[:array] index.values.each do |tuple| tuple[as] = tuple[as].to_a yield(tuple) end else index.values.each(&bl) end end
to_ast()
click to toggle source
# File lib/bmg/operator/group.rb, line 52 def to_ast [ :group, operand.to_ast, attrs.dup, as, options.dup ] end