Class: Alf::Engine::Take
Overview
Take only a frame of the input relation according to an (offset, limit) parameter.
Example:
res = [
{:name => "Jones", :price => 12.0, :id => 1},
{:name => "Smith", :price => 10.0, :id => 2},
{:name => "Blake", :price => 14.0, :id => 3}
{:name => "Adams", :price => 13.0, :id => 4}
]
Aggregate.new(res, 1, 2).to_a
# => [
# {:name => "Smith", :price => 10.0, :id => 2},
# {:name => "Blake", :price => 14.0, :id => 3}
# ]
Constant Summary
Constants included from Cog
Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS
Instance Attribute Summary collapse
-
#limit ⇒ Integer
readonly
The frame limit.
-
#offset ⇒ Integer
readonly
The frame offset.
-
#operand ⇒ Enumerable
readonly
The operand.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each ⇒ Object
- #arguments ⇒ Object
-
#initialize(operand, offset, limit, expr = nil, compiler = nil) ⇒ Take
constructor
Creates a Take instance.
Methods included from Cog
#children, #each, #options, #to_s
Methods included from Compiler::Cog
#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation
Constructor Details
#initialize(operand, offset, limit, expr = nil, compiler = nil) ⇒ Take
Creates a Take instance
34 35 36 37 38 39 |
# File 'lib/alf/engine/take.rb', line 34 def initialize(operand, offset, limit, expr = nil, compiler = nil) super(expr, compiler) @operand = operand @offset = offset @limit = limit end |
Instance Attribute Details
#limit ⇒ Integer (readonly)
Returns The frame limit.
31 32 33 |
# File 'lib/alf/engine/take.rb', line 31 def limit @limit end |
#offset ⇒ Integer (readonly)
Returns The frame offset.
28 29 30 |
# File 'lib/alf/engine/take.rb', line 28 def offset @offset end |
#operand ⇒ Enumerable (readonly)
Returns The operand.
25 26 27 |
# File 'lib/alf/engine/take.rb', line 25 def operand @operand end |
Instance Method Details
#_each ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/alf/engine/take.rb', line 42 def _each i = -1 operand.each do |tuple| next if (i += 1) < offset return if i >= offset+limit yield(tuple) end end |
#arguments ⇒ Object
51 52 53 |
# File 'lib/alf/engine/take.rb', line 51 def arguments [ offset, limit ] end |