Class: Axiom::Tuple
Overview
A set of objects representing a unique fact in a relation
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
private
The tuple data.
-
#header ⇒ Header
readonly
private
The tuple header.
Instance Method Summary collapse
-
#call(attribute) ⇒ Object
Lookup a value in the tuple given an attribute.
-
#extend(header, extensions) ⇒ Tuple
Extend a tuple with function results.
-
#initialize(header, data) ⇒ undefined
constructor
private
Initialize a Tuple.
-
#join(header, values) ⇒ Tuple
Append values to the tuple and return a new tuple.
-
#predicate ⇒ Function
private
Return the predicate matching the tuple.
-
#project(header) ⇒ Tuple
Return a tuple with only the specified attributes.
-
#to_ary ⇒ Array
Convert the Tuple into an Array.
Methods included from Aliasable
Constructor Details
#initialize(header, data) ⇒ 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 Tuple
36 37 38 39 |
# File 'lib/axiom/tuple.rb', line 36 def initialize(header, data) @header = header @data = Hash[header.zip(data)] end |
Instance Attribute Details
#data ⇒ Hash (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 tuple data
24 25 26 |
# File 'lib/axiom/tuple.rb', line 24 def data @data end |
#header ⇒ Header (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 tuple header
17 18 19 |
# File 'lib/axiom/tuple.rb', line 17 def header @header end |
Instance Method Details
#call(attribute) ⇒ Object
Lookup a value in the tuple given an attribute
51 52 53 |
# File 'lib/axiom/tuple.rb', line 51 def call(attribute) data.fetch(header.call(attribute)) end |
#extend(header, extensions) ⇒ Tuple
Extend a tuple with function results
100 101 102 103 104 105 |
# File 'lib/axiom/tuple.rb', line 100 def extend(header, extensions) join( header, extensions.map { |extension| Function.extract_value(extension, self) } ) end |
#join(header, values) ⇒ Tuple
Append values to the tuple and return a new tuple
83 84 85 |
# File 'lib/axiom/tuple.rb', line 83 def join(header, values) self.class.new(header, to_ary + values) end |
#predicate ⇒ Function
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.
Return the predicate matching the tuple
112 113 114 115 116 |
# File 'lib/axiom/tuple.rb', line 112 def predicate header.reduce(Function::Proposition::Tautology.instance) do |predicate, attribute| predicate.and(attribute.eq(attribute.call(self))) end end |
#project(header) ⇒ Tuple
Return a tuple with only the specified attributes
66 67 68 |
# File 'lib/axiom/tuple.rb', line 66 def project(header) self.class.new(header, data.values_at(*header)) end |
#to_ary ⇒ Array
Convert the Tuple into an Array
126 127 128 |
# File 'lib/axiom/tuple.rb', line 126 def to_ary data.values_at(*header).freeze end |