Sha256: 4c10a2591402cd3fa2a6a535e2d12f82ba6de954ee6d43d96b8c1954558ee7c6

Contents?: true

Size: 992 Bytes

Versions: 5

Compression:

Stored size: 992 Bytes

Contents

module Alf
  module Engine
    #
    # Provides hash-based grouping.
    #
    class Group::Hash < Cog

      # @return [Enumerable] The operand
      attr_reader :operand

      # @return [AttrList] Attributes to group
      attr_reader :attributes

      # @return [AttrName] Name of the new attribute
      attr_reader :as

      # @return [Boolean] Group all but specified attributes?
      attr_reader :allbut

      # Creates a Group::Hash instance
      def initialize(operand, attributes, as, allbut)
        @operand = operand
        @attributes = attributes
        @as = as
        @allbut = allbut
      end

      # (see Cog#each)
      def each(&block)
        atr, alb = @attributes, @allbut
        index = Materialize::Hash.new(operand, atr, !alb)
        index.each_pair do |k,v|
          grouped = Relation.new(Clip.new(v, atr, alb).to_set)
          yield k.merge(@as => grouped)
        end
      end

    end # class Group::Hash
  end # module Engine
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf-engine/alf/engine/group/hash.rb
alf-0.12.1 lib/alf-engine/alf/engine/group/hash.rb
alf-0.12.0 lib/alf-engine/alf/engine/group/hash.rb
alf-0.11.1 lib/alf-engine/alf/engine/group/hash.rb
alf-0.11.0 lib/alf-engine/alf/engine/group/hash.rb