Sha256: 61de4217eec4314d798251bb288573b77a6e39351defff545ec313da273e0b56

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

module Alf
  module Engine
    #
    # Provides hash-based grouping.
    #
    class Group::Hash
      include Group
      include 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, expr = nil, compiler = nil)
        super(expr, compiler)
        @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, expr)
        index.each_pair do |k,v|
          grouped = Clip.new(v, atr, alb).to_relation
          yield k.merge(@as => grouped)
        end
      end

      def arguments
        [ attributes, as ]
      end

      def options
        {allbut: allbut}
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/engine/group/hash.rb
alf-core-0.16.2 lib/alf/engine/group/hash.rb
alf-core-0.16.1 lib/alf/engine/group/hash.rb
alf-core-0.16.0 lib/alf/engine/group/hash.rb