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 `#{}`"
  end
  @name     = name
  @metadata = 
end

Instance Method Details

#==(other) ⇒ Object



77
78
79
80
81
# File 'lib/finitio/type.rb', line 77

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)


55
56
57
# File 'lib/finitio/type.rb', line 55

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)


51
52
53
# File 'lib/finitio/type.rb', line 51

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, force = false) ⇒ Object



35
36
37
38
39
40
# File 'lib/finitio/type.rb', line 35

def name=(n, force = false)
  if !@name.nil? && !force
    raise Error, "Name already set to `#{@name}` on #{self.class}"
  end
  @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)


83
84
85
# File 'lib/finitio/type.rb', line 83

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

#suppremum(other) ⇒ Object



59
60
61
62
# File 'lib/finitio/type.rb', line 59

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

#to_sObject



73
74
75
# File 'lib/finitio/type.rb', line 73

def to_s
  name.to_s
end

#unconstrainedObject



69
70
71
# File 'lib/finitio/type.rb', line 69

def unconstrained
  self
end