Class: Reddy::Namespace
- Inherits:
-
Object
- Object
- Reddy::Namespace
- Defined in:
- lib/reddy/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
21 22 23 24 25 26 27 28 29 |
# File 'lib/reddy/namespace.rb', line 21 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
48 49 50 51 52 53 54 |
# File 'lib/reddy/namespace.rb', line 48 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.
3 4 5 |
# File 'lib/reddy/namespace.rb', line 3 def fragment @fragment end |
#short ⇒ Object
Returns the value of attribute short.
3 4 5 |
# File 'lib/reddy/namespace.rb', line 3 def short @short end |
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/reddy/namespace.rb', line 3 def uri @uri end |
Instance Method Details
#bind(graph) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/reddy/namespace.rb', line 56 def bind(graph) if graph.class == Graph graph.bind(self) else raise end end |