Class: Gearbox::Vocabulary
- Inherits:
-
RDF::Vocabulary
- Object
- RDF::Vocabulary
- Gearbox::Vocabulary
- Defined in:
- lib/gearbox/vocabulary.rb
Class Method Summary collapse
-
.[](property) ⇒ RDF::URI
Returns the URI for the term ‘property` in this vocabulary.
- .lookup(property) ⇒ Object
-
.property(property, opts = {}) ⇒ void
Defines a vocabulary term called ‘property`.
Instance Method Summary collapse
-
#[](property) ⇒ URI
Returns the URI for the term ‘property` in this vocabulary.
-
#initialize(uri) ⇒ Vocabulary
constructor
A new instance of Vocabulary.
-
#inspect ⇒ String
Returns a developer-friendly representation of this vocabulary.
-
#to_s ⇒ String
Returns a string representation of this vocabulary.
-
#to_uri ⇒ URI
Returns the base URI for this vocabulary.
Constructor Details
#initialize(uri) ⇒ Vocabulary
Returns a new instance of Vocabulary.
93 94 95 96 97 98 |
# File 'lib/gearbox/vocabulary.rb', line 93 def initialize(uri) @uri = case uri when RDF::URI then uri.to_s else RDF::URI.parse(uri.to_s) ? uri.to_s : nil end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(property, *args, &block) ⇒ Object (protected)
135 136 137 138 139 140 141 |
# File 'lib/gearbox/vocabulary.rb', line 135 def method_missing(property, *args, &block) if args.empty? self[property] else raise ArgumentError.new("wrong number of arguments (#{args.size} for 0)") end end |
Class Method Details
.[](property) ⇒ RDF::URI
Returns the URI for the term ‘property` in this vocabulary.
56 57 58 |
# File 'lib/gearbox/vocabulary.rb', line 56 def [](property) RDF::URI.intern([to_s, property.to_s].join('')) end |
.lookup(property) ⇒ Object
60 61 62 |
# File 'lib/gearbox/vocabulary.rb', line 60 def lookup(property) end |
.property(property, opts = {}) ⇒ void
This method returns an undefined value.
Defines a vocabulary term called ‘property`.
46 47 48 49 |
# File 'lib/gearbox/vocabulary.rb', line 46 def property(property, opts={}) = class << self; self; end .send(:define_method, property) { self.lookup(property) } # class method end |
Instance Method Details
#[](property) ⇒ URI
Returns the URI for the term ‘property` in this vocabulary.
105 106 107 |
# File 'lib/gearbox/vocabulary.rb', line 105 def [](property) RDF::URI.intern([to_s, property.to_s].join('')) end |
#inspect ⇒ String
Returns a developer-friendly representation of this vocabulary.
129 130 131 |
# File 'lib/gearbox/vocabulary.rb', line 129 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s) end |
#to_s ⇒ String
Returns a string representation of this vocabulary.
121 122 123 |
# File 'lib/gearbox/vocabulary.rb', line 121 def to_s @uri.to_s end |
#to_uri ⇒ URI
Returns the base URI for this vocabulary.
113 114 115 |
# File 'lib/gearbox/vocabulary.rb', line 113 def to_uri RDF::URI.intern(to_s) end |