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.
-
#to_ary ⇒ Array
readonly
Convert the Tuple into an Array.
Instance Method Summary collapse
-
#extend(header, extensions) ⇒ Tuple
Extend a tuple with function results.
-
#fetch(attribute) ⇒ Object
Lookup a value in the tuple given an attribute.
-
#initialize(header, data) ⇒ undefined
constructor
private
Initialize a Tuple.
-
#inspect ⇒ String
Display the tuple data in a human readable form.
-
#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.
-
#rename(header) ⇒ Tuple
Rename a tuple to use a new header.
-
#size ⇒ Integer
The number of attributes.
-
#to_hash ⇒ Hash{Symbol => Object}
Coerce the tuple into a Hash.
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
46 47 48 49 50 |
# File 'lib/axiom/tuple.rb', line 46 def initialize(header, data) @header = header @to_ary = self.class.freezer.call(data) @data = Hash[header.zip(@to_ary)] 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 |
#to_ary ⇒ Array (readonly)
Convert the Tuple into an Array
34 35 36 |
# File 'lib/axiom/tuple.rb', line 34 def to_ary @to_ary end |
Instance Method Details
#extend(header, extensions) ⇒ Tuple
Extend a tuple with function results
94 95 96 97 98 99 |
# File 'lib/axiom/tuple.rb', line 94 def extend(header, extensions) join( header, extensions.map { |extension| Function.extract_value(extension, self) } ) end |
#fetch(attribute) ⇒ Object
Lookup a value in the tuple given an attribute
62 63 64 |
# File 'lib/axiom/tuple.rb', line 62 def fetch(attribute) data.fetch(header.fetch(attribute)) end |
#inspect ⇒ String
Display the tuple data in a human readable form
172 173 174 |
# File 'lib/axiom/tuple.rb', line 172 def inspect to_hash.inspect end |
#join(header, values) ⇒ Tuple
Append values to the tuple and return a new tuple
128 129 130 |
# File 'lib/axiom/tuple.rb', line 128 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
137 138 139 140 141 |
# File 'lib/axiom/tuple.rb', line 137 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
77 78 79 |
# File 'lib/axiom/tuple.rb', line 77 def project(header) self.class.new(header, data.values_at(*header)) end |
#rename(header) ⇒ Tuple
Rename a tuple to use a new header
111 112 113 |
# File 'lib/axiom/tuple.rb', line 111 def rename(header) self.class.new(header, to_ary) end |
#size ⇒ Integer
The number of attributes
160 161 162 |
# File 'lib/axiom/tuple.rb', line 160 def size header.size end |
#to_hash ⇒ Hash{Symbol => Object}
Coerce the tuple into a Hash
151 152 153 |
# File 'lib/axiom/tuple.rb', line 151 def to_hash Hash[data.map { |attribute, value| [attribute.name, value] }] end |