Class: Rena::Namespace
- Inherits:
-
Object
- Object
- Rena::Namespace
- Defined in:
- lib/rena/namespace.rb
Instance Attribute Summary collapse
-
#fragment ⇒ Object
Returns the value of attribute fragment.
-
#short ⇒ Object
Returns the value of attribute short.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #bind(graph) ⇒ Object
-
#initialize(uri, short, fragment = false) ⇒ Namespace
constructor
Creates a new namespace given a URI and the short name.
-
#method_missing(methodname, *args) ⇒ URIRef
Allows the construction of arbitrary URIs on the namespace.
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
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
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
#fragment ⇒ Object
Returns the value of attribute fragment.
6 7 8 |
# File 'lib/rena/namespace.rb', line 6 def fragment @fragment end |
#short ⇒ Object
Returns the value of attribute short.
6 7 8 |
# File 'lib/rena/namespace.rb', line 6 def short @short end |
#uri ⇒ Object
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 |