Class: Finitio::Type
Overview
Abstract class for Finitio type (generators).
Direct Known Subclasses
AdType, AliasType, AnyType, BuiltinType, MultiRelationType, MultiTupleType, ProxyType, RelationType, SeqType, SetType, StructType, SubType, TupleType, UnionType
Constant Summary
Constants included
from Metadata
Metadata::EMPTY_METADATA
Instance Method Summary
collapse
Methods included from Metadata
#metadata, #metadata=, #metadata?
Constructor Details
#initialize(name, metadata) ⇒ Type
Returns a new instance of Type.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/finitio/type.rb', line 8
def initialize(name, metadata)
unless name.nil? or name.is_a?(String)
raise ArgumentError, "String expected for type name, got `#{name}`"
end
unless metadata.nil? or metadata.is_a?(Hash)
raise ArgumentError, "Hash expected for metadata, got `#{metadata}`"
end
@name = name
@metadata = metadata
end
|
Instance Method Details
#==(other) ⇒ Object
61
62
63
64
65
|
# File 'lib/finitio/type.rb', line 61
def ==(other)
super || [ProxyType, AliasType].any?{|t|
other.is_a?(t) && other == self
}
end
|
#anonymous? ⇒ Boolean
19
20
21
|
# File 'lib/finitio/type.rb', line 19
def anonymous?
@name.nil?
end
|
#default_name ⇒ Object
27
28
29
|
# File 'lib/finitio/type.rb', line 27
def default_name
raise NotImplementedError, "Missing #{self.class.name}#default_name"
end
|
#dress(*args) ⇒ Object
53
54
55
|
# File 'lib/finitio/type.rb', line 53
def dress(*args)
raise NotImplementedError, "Missing #{self.class.name}#dress"
end
|
#include?(value) ⇒ Boolean
Check if ‘value` belongs to this type. Returns true if it’s the case, false otherwise.
For belonging to the type, ‘value` MUST be a valid representation, not an ’approximation’ or some ‘similar’ representation. In particular, returning true means that no dressing is required for using ‘value` as a proper one. Similarly, the method MUST always return true on a value directly obtained through `dress`.
49
50
51
|
# File 'lib/finitio/type.rb', line 49
def include?(value)
raise NotImplementedError, "Missing #{self.class.name}#include?"
end
|
#name ⇒ Object
31
32
33
|
# File 'lib/finitio/type.rb', line 31
def name
@name || default_name
end
|
#name=(n) ⇒ Object
35
36
37
38
|
# File 'lib/finitio/type.rb', line 35
def name=(n)
raise Error, "Name already set to `#{@name}`" unless @name.nil?
@name = n
end
|
#named? ⇒ Boolean
23
24
25
|
# File 'lib/finitio/type.rb', line 23
def named?
!anonymous?
end
|
#to_s ⇒ Object
57
58
59
|
# File 'lib/finitio/type.rb', line 57
def to_s
name.to_s
end
|