class Bmg::Operator::Page

Page operator.

Takes the n-th page according to some tuple ordering and page size

Constants

DEFAULT_OPTIONS

Attributes

options[R]
ordering[R]
page_index[R]

Public Class Methods

new(type, operand, ordering, page_index, options) click to toggle source
# File lib/bmg/operator/page.rb, line 17
def initialize(type, operand, ordering, page_index, options)
  raise ArgumentError, "Page index must be > 0" if page_index <= 0
  @type = type
  @operand = operand
  @ordering = ordering
  @page_index = page_index
  @options = DEFAULT_OPTIONS.merge(options)
end

Public Instance Methods

each(&bl) click to toggle source
# File lib/bmg/operator/page.rb, line 32
def each(&bl)
  return to_enum unless block_given?
  page_size = options[:page_size]
  @operand.to_a
    .sort(&comparator)
    .drop(page_size * (page_index-1))
    .take(page_size)
    .each(&bl)
end
to_ast() click to toggle source
# File lib/bmg/operator/page.rb, line 42
def to_ast
  [ :page, operand.to_ast, ordering.dup, page_index, options.dup ]
end