class Axiom::Relation::Operation::Offset
A class representing an offset relation
Attributes
The relation sort order
@return [Operation::Sorted::DirectionSet]
@api private
Return the offset
@example
offset = offset_relation.offset
@return [Integer]
@api public
Public Class Methods
Instantiate a new Offset
@example
offset_relation = Offset.new(operand, offset)
@param [Relation] operand
the relation to offset
@param [Integer] offset
the offset of the operand to drop
@return [Offset]
@api public
Axiom::Relation::Operation::Unary::new
# File lib/axiom/relation/operation/offset.rb, line 42 def self.new(operand, offset) assert_sorted_operand(operand) assert_valid_offset(offset) super end
Initialize an Offset
@param [Relation] operand
the relation to offset
@param [Integer] offset
the offset of the operand to drop
@return [undefined]
@api private
Axiom::Relation::Operation::Unary::new
# File lib/axiom/relation/operation/offset.rb, line 92 def initialize(operand, offset) super(operand) @offset = offset @directions = operand.directions end
Private Class Methods
Assert the operand is sorted
@param [Relation] operand
@return [undefined]
@raise [SortededRelationRequiredError]
raised if the operand is unsorted
@api private
# File lib/axiom/relation/operation/offset.rb, line 58 def self.assert_sorted_operand(operand) if operand.header.size != operand.directions.size fail SortededRelationRequiredError, 'can only offset a sorted operand' end end
Assert the offset is valid
@param [Integer] offset
@return [undefined]
@raise [InvalidOffsetError]
raised if the offset is less than 0
@api private
# File lib/axiom/relation/operation/offset.rb, line 74 def self.assert_valid_offset(offset) if offset.nil? || offset < 0 fail InvalidOffsetError, "offset must be greater than or equal to 0, but was #{offset.inspect}" end end
Public Instance Methods
Raise an exception when deleting from the Offset
@example
offset.delete(other) # => ImmutableRelationError raised
@return [undefined]
@raise [ImmutableRelationError]
raised when deleting from the offset
@api public
# File lib/axiom/relation/operation/offset.rb, line 146 def delete(*) fail ImmutableRelationError, 'deleting from an offset is impossible' end
Iterate over each tuple in the set
@example
offset_relation = Offset.new(operand, offset) offset_relation.each { |tuple| ... }
@yield [tuple]
@yieldparam [Tuple] tuple
each tuple in the set
@return [self]
@api public
# File lib/axiom/relation/operation/offset.rb, line 112 def each return to_enum unless block_given? operand.each_with_index do |tuple, index| yield tuple if index >= @offset end self end
Raise an exception when inserting into the Offset
@example
offset.insert(other) # => ImmutableRelationError raised
@return [undefined]
@raise [ImmutableRelationError]
raised when inserting into the offset
@api public
# File lib/axiom/relation/operation/offset.rb, line 131 def insert(*) fail ImmutableRelationError, 'inserting into an offset is impossible' end