Class: Axiom::Relation::Operation::Offset

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

Overview

A class representing an offset 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, offset) ⇒ 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 an Offset

Parameters:

  • operand (Relation)

    the relation to offset

  • offset (Integer)

    the offset of the operand to drop



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

def initialize(operand, offset)
  super(operand)
  @offset     = offset
  @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/offset.rb', line 27

def directions
  @directions
end

#offsetInteger (readonly)

Return the offset

Examples:

offset = offset_relation.offset

Returns:

  • (Integer)


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

def offset
  @offset
end

Class Method Details

.new(operand, offset) ⇒ Offset

Instantiate a new Offset

Examples:

offset_relation = Offset.new(operand, offset)

Parameters:

  • operand (Relation)

    the relation to offset

  • offset (Integer)

    the offset of the operand to drop

Returns:



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

def self.new(operand, offset)
  assert_sorted_operand(operand)
  assert_valid_offset(offset)
  super
end

Instance Method Details

#deleteundefined

Raise an exception when deleting from the Offset

Examples:

offset.delete(other)  # => ImmutableRelationError raised

Returns:

  • (undefined)

Raises:



146
147
148
# File 'lib/axiom/relation/operation/offset.rb', line 146

def delete(*)
  fail ImmutableRelationError, 'deleting from an offset is impossible'
end

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

Iterate over each tuple in the set

Examples:

offset_relation = Offset.new(operand, offset)
offset_relation.each { |tuple| ... }

Yields:

  • (tuple)

Yield Parameters:

  • tuple (Tuple)

    each tuple in the set

Returns:

  • (self)


112
113
114
115
116
117
118
# 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

#insertundefined

Raise an exception when inserting into the Offset

Examples:

offset.insert(other)  # => ImmutableRelationError raised

Returns:

  • (undefined)

Raises:



131
132
133
# File 'lib/axiom/relation/operation/offset.rb', line 131

def insert(*)
  fail ImmutableRelationError, 'inserting into an offset is impossible'
end