Class: Rena::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/rena/namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, short, fragment = false) ⇒ Namespace

Creates a new namespace given a URI and the short name.

Example

Namespace.new("http://xmlns.com/foaf/0.1/", "foaf") # => returns a new Foaf namespace

Returns

Raises:

  • (Error)

    Checks validity of the desired shortname and raises if it is incorrect.

Author:

  • Tom Morris, Pius Uzamere



24
25
26
27
28
29
30
31
32
# File 'lib/rena/namespace.rb', line 24

def initialize(uri, short, fragment = false)
  @uri = uri
  @fragment = fragment
  if shortname_valid?(short)
    @short = short
  else
    raise
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodname, *args) ⇒ URIRef

Allows the construction of arbitrary URIs on the namespace.

Example

foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf"); foaf.knows # => returns a new URIRef with URI "http://xmlns.com/foaf/0.1/knows"
foaf = Namespace.new("http://xmlns.com/foaf/0.1/", "foaf", true); foaf.knows # => returns a new URIRef with URI "http://xmlns.com/foaf/0.1/#knows"

Returns

Raises:

  • (Error)

    Checks validity of the desired shortname and raises if it is incorrect.

Author:

  • Tom Morris, Pius Uzamere



51
52
53
54
55
56
57
# File 'lib/rena/namespace.rb', line 51

def method_missing(methodname, *args)
  unless fragment
    URIRef.new(@uri + methodname.to_s)
  else
    URIRef.new(@uri + '#' + methodname.to_s)
  end
end

Instance Attribute Details

#fragmentObject

Returns the value of attribute fragment.



6
7
8
# File 'lib/rena/namespace.rb', line 6

def fragment
  @fragment
end

#shortObject

Returns the value of attribute short.



6
7
8
# File 'lib/rena/namespace.rb', line 6

def short
  @short
end

#uriObject

Returns the value of attribute uri.



6
7
8
# File 'lib/rena/namespace.rb', line 6

def uri
  @uri
end

Instance Method Details

#bind(graph) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/rena/namespace.rb', line 59

def bind(graph)
  if graph.class == Graph
    graph.bind(self)
  else
    raise
  end
end