@@ -70,11 +70,15 @@ class << self
7070 # @return [Enumerator]
7171 def each ( &block )
7272 if self . equal? ( Vocabulary )
73- # This is needed since all vocabulary classes are defined using
74- # Ruby's autoloading facility, meaning that `@@subclasses` will be
75- # empty until each subclass has been touched or require'd.
76- RDF ::VOCABS . each { |v , p | RDF . const_get ( p [ :class_name ] . to_sym ) unless v == :rdf }
77- @@subclasses . select ( &:name ) . each ( &block )
73+ if @vocabs
74+ @vocabs . select ( &:name ) . each ( &block )
75+ else
76+ # This is needed since all vocabulary classes are defined using
77+ # Ruby's autoloading facility, meaning that `@@subclasses` will be
78+ # empty until each subclass has been touched or require'd.
79+ RDF ::VOCABS . each { |v , p | RDF . const_get ( p [ :class_name ] . to_sym ) unless v == :rdf }
80+ @@subclasses . select ( &:name ) . each ( &block )
81+ end
7882 else
7983 __properties__ . each ( &block )
8084 end
@@ -96,6 +100,38 @@ def from_sym(sym)
96100 RDF . const_get ( sym . to_sym )
97101 end
98102
103+ ##
104+ # Limits iteration over vocabularies to just those selected
105+ #
106+ # @example limit to set of vocabularies by symbol
107+ # RDF::Vocabulary.limit_vocabs(:rdf, :rdfs
108+ # RDF::Vocabulary.find_term('http://www.w3.org/2000/01/rdf-schema#Resource').pname
109+ # # => 'rdfs:Resource'
110+ #
111+ # @example limit to set of vocabularies by class name
112+ # RDF::Vocabulary.limit_vocabs(RDF::RDFV, RDF::RDFS)
113+ # RDF::Vocabulary.find_term('http://www.w3.org/2000/01/rdf-schema#Resource').pname
114+ # # => 'rdfs:Resource'
115+ #
116+ # @param [Array<symbol, RDF::Vocabulary>] vocabs
117+ # A list of vocabularies (symbols or classes) which may
118+ # be returned by {Vocabulary.each}. Also limits
119+ # vocabularies that will be inspeced for other methods.
120+ # Set to nil, or an empty array to reset.
121+ # @return [Array<RDF::Vocabulary>]
122+ def limit_vocabs ( *vocabs )
123+ @vocabs = if Array ( vocabs ) . empty?
124+ nil
125+ else
126+ vocabs . map do |vocab |
127+ vocab = :rdfv if vocab == :rdf
128+ vocab . is_a? ( Symbol ) && RDF ::VOCABS . key? ( vocab ) ?
129+ RDF . const_get ( RDF ::VOCABS [ vocab ] [ :class_name ] . to_sym ) :
130+ vocab
131+ end . compact
132+ end
133+ end
134+
99135 ##
100136 # Is this a strict vocabulary, or a liberal vocabulary allowing arbitrary properties?
101137 def strict? ; false ; end
@@ -610,7 +646,6 @@ def inherited(subclass) # @private
610646 unless @@uri . nil?
611647 @@subclasses << subclass unless %w( http://www.w3.org/1999/02/22-rdf-syntax-ns# ) . include? ( @@uri )
612648 subclass . send ( :private_class_method , :new )
613- #vocab_map[subclass.__prefix__] ||= {uri: @@uri, class_name: subclass.__name__.split('::').last.downcase}
614649 @@uris [ subclass ] = @@uri
615650 @@uri = nil
616651 end
0 commit comments