Class: Finitio::System

Inherits:
Object
  • Object
show all
Defined in:
lib/finitio/system.rb

Overview

A System is a collection of named Finitio types.

Instance Method Summary collapse

Constructor Details

#initialize(types = {}) ⇒ System

Returns a new instance of System.



7
8
9
# File 'lib/finitio/system.rb', line 7

def initialize(types = {})
  @types = types
end

Instance Method Details

#add_type(type, name = nil, metadata = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/finitio/system.rb', line 11

def add_type(type, name = nil,  = nil)
  type = factory.type(type, name, )

  if @types.has_key?(type.name)
    raise Error, "Duplicate type name `#{type.name}`"
  end

  @types[type.name] = type
end

#dress(*args, &bl) ⇒ Object

Raises:



44
45
46
47
# File 'lib/finitio/system.rb', line 44

def dress(*args, &bl)
  raise Error, "No main type." unless main
  main.dress(*args, &bl)
end

#dupObject



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

def dup
  System.new(@types.dup)
end

#factoryObject



34
35
36
# File 'lib/finitio/system.rb', line 34

def factory
  @factory ||= TypeFactory.new
end

#fetch(name, &bl) ⇒ Object



30
31
32
# File 'lib/finitio/system.rb', line 30

def fetch(name, &bl)
  @types.fetch(name, &bl)
end

#get_type(name) ⇒ Object Also known as: []



21
22
23
# File 'lib/finitio/system.rb', line 21

def get_type(name)
  @types[name] || @types[name.to_s]
end

#inspectObject



54
55
56
# File 'lib/finitio/system.rb', line 54

def inspect
  @types.each_pair.map{|k,v| "#{k} = #{v}" }.join("\n")
end

#mainObject



26
27
28
# File 'lib/finitio/system.rb', line 26

def main
  self['Main']
end

#parse(source) ⇒ Object



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

def parse(source)
  require_relative "syntax"
  Syntax.compile(source, self.dup)
end