Method: RDF::Format.for
- Defined in:
- lib/rdf/format.rb
.for(format) ⇒ Class .for(filename) ⇒ Class .for(options) ⇒ Class
Finds an RDF serialization format class based on the given criteria. If multiple formats are identified, the last one found is returned; this allows descrimination of equivalent formats based on load order.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rdf/format.rb', line 173 def self.for(*arg, &block) case arg.length when 0 then arg = nil when 1 then arg = arg.first else raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}." end = arg.is_a?(Hash) ? arg : {} = {sample: block}.merge() if block_given? formats = case arg when String, RDF::URI # Find a format based on the file name self.each(file_name: arg, **).to_a when Symbol # Try to find a match based on the full class name # We want this to work even if autoloading fails classes = self.each(**).select {|f| f.symbols.include?(arg)} if classes.empty? classes = case arg when :ntriples then [RDF::NTriples::Format] when :nquads then [RDF::NQuads::Format] else [] end end classes else self.each(**.merge(all_if_none: false)).to_a end # Return the last detected format formats.last end |