Class: RDF::Vocabulary
- Inherits:
-
Object
- Object
- RDF::Vocabulary
- Extended by:
- Enumerable
- Defined in:
- lib/rdf/vocab.rb
Overview
A Vocabulary represents an RDFS or OWL vocabulary.
### Vocabularies:
The following vocabularies are pre-defined for your convenience:
-
RDF - Resource Description Framework (RDF)
-
CC - Creative Commons (CC)
-
CERT - W3 Authentication Certificate (CERT)
-
DC - Dublin Core (DC)
-
DC11 - Dublin Core 1.1 (DC11) deprecated
-
DOAP - Description of a Project (DOAP)
-
EXIF - Exchangeable Image File Format (EXIF)
-
FOAF - Friend of a Friend (FOAF)
-
GEO - WGS84 Geo Positioning (GEO)
-
HTTP - Hypertext Transfer Protocol (HTTP)
-
OWL - Web Ontology Language (OWL)
-
RDFS - RDF Schema (RDFS)
-
RSA - W3 RSA Keys (RSA)
-
RSS - RDF Site Summary (RSS)
-
SIOC - Semantically-Interlinked Online Communities (SIOC)
-
SKOS - Simple Knowledge Organization System (SKOS)
-
WOT - Web of Trust (WOT)
-
XHTML - Extensible HyperText Markup Language (XHTML)
-
XSD - XML Schema (XSD)
Direct Known Subclasses
CC, CERT, DC, DC11, DOAP, EXIF, FOAF, GEO, HTTP, OWL, RDFS, RSA, RSS, SIOC, SKOS, WOT, XHTML, XSD
Class Method Summary collapse
-
.[](property) ⇒ RDF::URI
Returns the URI for the term ‘property` in this vocabulary.
-
.__prefix__ ⇒ Symbol
Returns a suggested CURIE/QName prefix for this vocabulary class.
-
.each {|klass| ... } ⇒ Enumerator
Enumerates known RDF vocabulary classes.
-
.inspect ⇒ String
Returns a developer-friendly representation of this vocabulary class.
-
.property(property) ⇒ void
Defines a vocabulary term called ‘property`.
-
.to_s ⇒ String
Returns a string representation of this vocabulary class.
-
.to_uri ⇒ RDF::URI
Returns the base URI for this vocabulary class.
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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(property, *args, &block) ⇒ Object (protected)
201 202 203 204 205 206 207 |
# File 'lib/rdf/vocab.rb', line 201 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.
84 85 86 |
# File 'lib/rdf/vocab.rb', line 84 def self.[](property) RDF::URI.intern([to_s, property.to_s].join('')) end |
.__prefix__ ⇒ Symbol
Returns a suggested CURIE/QName prefix for this vocabulary class.
127 128 129 |
# File 'lib/rdf/vocab.rb', line 127 def self.__prefix__ self.__name__.split('::').last.downcase.to_sym end |
.each {|klass| ... } ⇒ Enumerator
Enumerates known RDF vocabulary classes.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rdf/vocab.rb', line 57 def self.each(&block) if self.equal?(Vocabulary) # This is needed since all vocabulary classes are defined using # Ruby's autoloading facility, meaning that `@@subclasses` will be # empty until each subclass has been touched or require'd. RDF::VOCABS.each { |v| require "rdf/vocab/#{v}" unless v == :rdf } @@subclasses.each(&block) else # TODO: should enumerate vocabulary-specific defined properties. end end |
.inspect ⇒ String
Returns a developer-friendly representation of this vocabulary class.
108 109 110 111 112 113 114 |
# File 'lib/rdf/vocab.rb', line 108 def self.inspect if self == Vocabulary self.to_s else sprintf("%s(%s)", superclass.to_s, to_s) end end |
.property(property) ⇒ void
This method returns an undefined value.
Defines a vocabulary term called ‘property`.
74 75 76 77 |
# File 'lib/rdf/vocab.rb', line 74 def self.property(property) = class << self; self; end .send(:define_method, property) { self[property] } # class method end |
.to_s ⇒ String
Returns a string representation of this vocabulary class.
100 101 102 |
# File 'lib/rdf/vocab.rb', line 100 def self.to_s @@uris.has_key?(self) ? @@uris[self].to_s : super end |
Instance Method Details
#[](property) ⇒ URI
Returns the URI for the term ‘property` in this vocabulary.
148 149 150 |
# File 'lib/rdf/vocab.rb', line 148 def [](property) RDF::URI.intern([to_s, property.to_s].join('')) end |
#inspect ⇒ String
Returns a developer-friendly representation of this vocabulary.
172 173 174 |
# File 'lib/rdf/vocab.rb', line 172 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s) end |
#to_s ⇒ String
Returns a string representation of this vocabulary.
164 165 166 |
# File 'lib/rdf/vocab.rb', line 164 def to_s @uri.to_s end |