Class: Finitio::Type

Inherits:
Object
  • Object
show all
Includes:
Metadata
Defined in:
lib/finitio/type.rb

Overview

Abstract class for Finitio type (generators).

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, )
  unless name.nil? or name.is_a?(String)
    raise ArgumentError, "String expected for type name, got `#{name}`"
  end
  unless .nil? or .is_a?(Hash)
    raise ArgumentError, "Hash expected for metadata, got `#{metadata}`"
  end
  @name     = name
   = 
end

Instance Method Details

#==(other) ⇒ Object



75
76
77
78
79
# File 'lib/finitio/type.rb', line 75

def ==(other)
  super || [ProxyType, AliasType].any?{|t|
    other.is_a?(t) && other == self
  }
end

#anonymous?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/finitio/type.rb', line 19

def anonymous?
  @name.nil?
end

#default_nameObject

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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`.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/finitio/type.rb', line 49

def include?(value)
  raise NotImplementedError, "Missing #{self.class.name}#include?"
end

#nameObject



31
32
33
# File 'lib/finitio/type.rb', line 31

def name
  @name || default_name
end

#name=(n) ⇒ Object

Raises:



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/finitio/type.rb', line 23

def named?
  !anonymous?
end

#resolve_proxies(system) ⇒ Object

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/finitio/type.rb', line 81

def resolve_proxies(system)
  raise NotImplementedError, "resolve_proxies must be overriden"
end

#suppremum(other) ⇒ Object



57
58
59
60
# File 'lib/finitio/type.rb', line 57

def suppremum(other)
  return self if other == self
  other._suppremum(self)
end

#to_sObject



71
72
73
# File 'lib/finitio/type.rb', line 71

def to_s
  name.to_s
end

#unconstrainedObject



67
68
69
# File 'lib/finitio/type.rb', line 67

def unconstrained
  self
end