Class: Alf::Engine::Clip

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/alf/engine/clip.rb

Overview

Clips input tuples keeping (all but) specific attributes only.

Example:

operand = [
  {:name => "Jones", :city => "London"}, 
  {:name => "Smith", :city => "Paris"}
]

Clip.new(operand, AttrList[:name], false).to_a
# => [
#      {:name => "Jones"}, 
#      {:name => "Smith"}
#    ]

Clip.new(operand, AttrList[:name], true).to_a
# => [
#      {:city => "London"}, 
#      {:city => "Paris"}
#    ]

Constant Summary

Constants included from Cog

Alf::Engine::Cog::EMPTY_CHILDREN, Alf::Engine::Cog::EMPTY_OPTIONS

Instance Attribute Summary collapse

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

Methods included from Cog

#children, #each, #to_s

Methods included from Compiler::Cog

#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation

Constructor Details

#initialize(operand, attributes, allbut, expr = nil, compiler = nil) ⇒ Clip

Creates an Clip instance


38
39
40
41
42
43
# File 'lib/alf/engine/clip.rb', line 38

def initialize(operand, attributes, allbut, expr = nil, compiler = nil)
  super(expr, compiler)
  @operand = operand
  @attributes = attributes
  @allbut = allbut
end

Instance Attribute Details

#allbutBoolean (readonly)

Returns Clip *all but* attributes?

Returns:

  • (Boolean)

    Clip *all but* attributes?


35
36
37
# File 'lib/alf/engine/clip.rb', line 35

def allbut
  @allbut
end

#attributesAttrList (readonly)

Returns List of attributes for clipping

Returns:

  • (AttrList)

    List of attributes for clipping


32
33
34
# File 'lib/alf/engine/clip.rb', line 32

def attributes
  @attributes
end

#operandEnumerable (readonly)

Returns The operand

Returns:

  • (Enumerable)

    The operand


29
30
31
# File 'lib/alf/engine/clip.rb', line 29

def operand
  @operand
end

Instance Method Details

#_eachObject


46
47
48
49
50
# File 'lib/alf/engine/clip.rb', line 46

def _each
  @operand.each do |tuple|
    yield @attributes.project_tuple(tuple, @allbut)
  end
end

#argumentsObject


52
53
54
# File 'lib/alf/engine/clip.rb', line 52

def arguments
  [attributes]
end

#optionsObject


56
57
58
# File 'lib/alf/engine/clip.rb', line 56

def options
  {allbut: allbut}
end