Class: Axiom::Relation::Operation::Limit

Inherits:
Axiom::Relation show all
Includes:
Unary
Defined in:
lib/axiom/relation/operation/limit.rb

Overview

A class representing a limited relation

Defined Under Namespace

Modules: Methods

Instance Attribute Summary collapse

Attributes included from Operation::Unary

#operand

Attributes inherited from Axiom::Relation

#header

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Axiom::Relation

#==, #[], #empty?, #include?, #materialize, #materialized?, #replace

Methods included from Visitable

#accept

Constructor Details

#initialize(operand, limit) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a Limit

Parameters:

  • operand (Relation)

    the relation to limit

  • limit (Integer)

    the maximum number of tuples in the limited relation



92
93
94
95
96
# File 'lib/axiom/relation/operation/limit.rb', line 92

def initialize(operand, limit)
  super(operand)
  @limit      = limit
  @directions = operand.directions
end

Instance Attribute Details

#directionsOperation::Sorted::DirectionSet (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The relation sort order



27
28
29
# File 'lib/axiom/relation/operation/limit.rb', line 27

def directions
  @directions
end

#limitInteger (readonly)

Return the limit

Examples:

limit = limited_relation.limit

Returns:

  • (Integer)


20
21
22
# File 'lib/axiom/relation/operation/limit.rb', line 20

def limit
  @limit
end

Class Method Details

.new(operand, limit) ⇒ Limit

Instantiate a new Limit

Examples:

limited_relation = Limit.new(operand, limit)

Parameters:

  • operand (Relation)

    the relation to limit

  • limit (Integer)

    the maximum number of tuples in the limited relation

Returns:



42
43
44
45
46
# File 'lib/axiom/relation/operation/limit.rb', line 42

def self.new(operand, limit)
  assert_sorted_operand(operand)
  assert_valid_limit(limit)
  super
end

Instance Method Details

#deleteundefined

Raise an exception when deleting from the Limit

Examples:

limit.delete(other)  # => ImmutableRelationError raised

Returns:

  • (undefined)

Raises:



147
148
149
# File 'lib/axiom/relation/operation/limit.rb', line 147

def delete(*)
  fail ImmutableRelationError, 'deleting from a limit is impossible'
end

#each {|tuple| ... } ⇒ self

Iterate over each tuple in the set

Examples:

limited_relation = Limit.new(operand, limit)
limited_relation.each { |tuple| ... }

Yields:

  • (tuple)

Yield Parameters:

  • tuple (Tuple)

    each tuple in the set

Returns:

  • (self)


112
113
114
115
116
117
118
119
# File 'lib/axiom/relation/operation/limit.rb', line 112

def each
  return to_enum unless block_given?
  operand.each_with_index do |tuple, index|
    break if @limit == index
    yield tuple
  end
  self
end

#insertundefined

Raise an exception when inserting into the Limit

Examples:

limit.insert(other)  # => ImmutableRelationError raised

Returns:

  • (undefined)

Raises:



132
133
134
# File 'lib/axiom/relation/operation/limit.rb', line 132

def insert(*)
  fail ImmutableRelationError, 'inserting into a limit is impossible'
end