Sha256: f1fec10aa75958d52c2f02b0d48b1efe7b2b0814712e89b87a6d9ca77961647c

Contents?: true

Size: 910 Bytes

Versions: 5

Compression:

Stored size: 910 Bytes

Contents

module Alf
  module Engine
    #
    # Unwraps a tuple attribute
    #
    class Unwrap
      include Cog

      # @return [Enumerable] The operand
      attr_reader :operand

      # @return [AttrName] Name of the attribute to unwrap
      attr_reader :attribute

      # Creates a SetAttr instance
      def initialize(operand, attribute, expr = nil, compiler = nil)
        super(expr, compiler)
        @operand = operand
        @attribute = attribute
      end

      # (see Cog#each)
      def _each
        operand.each do |tuple|
          tuple   = tuple.dup
          tuple   = tuple.to_hash unless tuple.is_a?(Hash)
          wrapped = tuple.delete(@attribute) || {}
          wrapped = symbolize(wrapped)
          tuple.merge!(wrapped)
          yield tuple
        end
      end

      def arguments
        [ attribute ]
      end

    end # class Unwrap
  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/unwrap.rb
alf-core-0.16.2 lib/alf/engine/unwrap.rb
alf-core-0.16.1 lib/alf/engine/unwrap.rb
alf-core-0.16.0 lib/alf/engine/unwrap.rb
alf-core-0.15.0 lib/alf/engine/unwrap.rb