Class: Trith::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/trith/function.rb

Overview

A Trith function.

Constant Summary

URI =
RDF::URI("http://trith.org/lang/Function").freeze

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Function) initialize(id = nil, options = {}, &block)

A new instance of Function

Parameters:

  • (RDF::Resource) id (defaults to: nil)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/trith/function.rb', line 18

def initialize(id = nil, options = {}, &block)
  @id = case id
    when nil then RDF::Node.new
    when RDF::Resource then id
    else RDF::Resource.new(id)
  end

  if block_given?
    case block.arity
      when 1 then block.call(self)
      else self.instance_eval(&block)
    end
  end
end

Instance Attribute Details

- (String) comment

Returns:

  • (String)


14
15
16
# File 'lib/trith/function.rb', line 14

def comment
  @comment
end

- (RDF::Resource) id

Returns:

  • (RDF::Resource)


8
9
10
# File 'lib/trith/function.rb', line 8

def id
  @id
end

- (Symbol) label

Returns:

  • (Symbol)


11
12
13
# File 'lib/trith/function.rb', line 11

def label
  @label ||= id.to_s.sub(/^(.*)\/([^\/]+)$/, '\2').to_sym # FIXME
end

Instance Method Details

- (Enumerator) each_statement(&block)

Returns:

  • (Enumerator)


80
81
82
# File 'lib/trith/function.rb', line 80

def each_statement(&block)
  to_rdf.each_statement(&block)
end

- (String) inspect

Returns a developer-friendly representation of this function.

Returns:

  • (String)


62
63
64
# File 'lib/trith/function.rb', line 62

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, id.to_s)
end

- (Boolean) is_primitive? Also known as: is_native?

Returns true if this is a primitive function.

Primitive functions are implemented directly in the Trith interpreter or compiler using native code.

Returns:

  • (Boolean)


52
53
54
# File 'lib/trith/function.rb', line 52

def is_primitive?
  false # TODO
end

- (Enumerable<Symbol>) labels

Returns:

  • (Enumerable<Symbol>)


41
42
43
# File 'lib/trith/function.rb', line 41

def labels
  [label] # FIXME
end

- (RDF::Graph) to_rdf

Returns the RDF representation of this function.

Returns:

  • (RDF::Graph)


70
71
72
73
74
75
76
# File 'lib/trith/function.rb', line 70

def to_rdf
  RDF::Graph.new(id) do |graph|
    graph << [id, RDF.type, Trith::Function::URI]
    graph << [id, RDF::RDFS.label, label]   if label
    graph << [id, RDF::RDFS.comment, label] if comment
  end
end