Sha256: 9cd8a26d7f4c5889863d14552f62cbeab7945f8bebcc10751c06f5e634829311

Contents?: true

Size: 999 Bytes

Versions: 5

Compression:

Stored size: 999 Bytes

Contents

module Alf
  module Engine
    #
    # Wraps attributes under as a sub-tuple
    #
    class Wrap
      include Cog

      # @return [Enumerable] The operand
      attr_reader :operand

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

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

      # @return [Boolean] Allbut wrapping?
      attr_reader :allbut

      # Creates a SetAttr 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
        operand.each do |tuple|
          rest, key = @attributes.split_tuple(tuple, @allbut)
          key[@as] = rest
          yield key
        end
      end

      def arguments
        [ attribute ]
      end

    end # class Wrap
  end # module Engine
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

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