Class: Finitio::TupleType
- Includes:
- HashBasedType, HeadingBasedType
- Defined in:
- lib/finitio/type/tuple_type.rb
Overview
The Tuple type generator allows capturing information facts. For instance, a Point type could be defined as follows:
Point = {r: Length, theta: Angle}
This class allows capturing those information types, as in:
Length = BuiltinType.new(Fixnum)
Angle = BuiltinType.new(Float)
Point = TupleType.new(Heading.new([
Attribute.new(:r, Length),
Attribute.new(:theta, Angle)
]))
A Hash with Symbol as keys is used as concrete ruby representation for tuples. The values map to the concrete representations of each attribute type:
R(Point) = Hash[r: R(Length), theta: R(Angle)]
= Hash[r: Fixnum, theta: Float]
Accordingly, the ‘dress` transformation function has the signature below. It expects it’s Alpha/Object argument to be a Hash with all and only the expected keys (either as Symbols or Strings). The ‘dress` function applies on every attribute value according to their respective type.
dress :: Alpha -> Point throws TypeError
dress :: Object -> Hash[r: Fixnum, theta: Float] throws TypeError
Constant Summary
Constants included from Metadata
Instance Attribute Summary
Attributes included from HeadingBasedType
Instance Method Summary collapse
- #default_name ⇒ Object
-
#initialize(heading, name = nil, metadata = nil) ⇒ TupleType
constructor
A new instance of TupleType.
- #suppremum(other) ⇒ Object
Methods included from HashBasedType
#dress, #generate_data, #include?, #representator
Methods included from HeadingBasedType
#==, #[], #hash, #resolve_proxies, #unconstrained
Methods inherited from Type
#==, #anonymous?, #dress, #include?, #name, #name=, #named?, #resolve_proxies, #to_s, #unconstrained
Methods included from Metadata
#metadata, #metadata=, #metadata?
Constructor Details
#initialize(heading, name = nil, metadata = nil) ⇒ TupleType
Returns a new instance of TupleType.
36 37 38 39 40 41 |
# File 'lib/finitio/type/tuple_type.rb', line 36 def initialize(heading, name = nil, = nil) super if heading.multi? raise ArgumentError, "Multi heading forbidden" end end |
Instance Method Details
#default_name ⇒ Object
43 44 45 |
# File 'lib/finitio/type/tuple_type.rb', line 43 def default_name "{#{heading.to_name}}" end |
#suppremum(other) ⇒ Object
47 48 49 |
# File 'lib/finitio/type/tuple_type.rb', line 47 def suppremum(other) super(other, TupleType, MultiTupleType) end |