@@ -23,7 +23,9 @@ module RDF
2323 #
2424 # @example Defining a new RDF serialization format class
2525 # class RDF::NTriples::Format < RDF::Format
26- # content_type 'application/n-triples', extension: :nt
26+ # content_type 'application/n-triples',
27+ # extension: :nt,
28+ # uri: RDF::URI("http://www.w3.org/ns/formats/N-Triples")
2729 # content_encoding 'utf-8'
2830 #
2931 # reader RDF::NTriples::Reader
@@ -222,6 +224,19 @@ def self.file_extensions
222224 @@file_extensions
223225 end
224226
227+ ##
228+ # Returns the unique URI for the format.
229+ #
230+ # @example retrieving a list of supported file format URIs
231+ #
232+ # RDF::Format.uris.keys
233+ #
234+ # @see https://www.w3.org/ns/formats/
235+ # @return [Hash{Symbol => URI}]
236+ def self . uris
237+ @@uris
238+ end
239+
225240 ##
226241 # Returns the set of format symbols for available RDF::Reader subclasses.
227242 #
@@ -465,6 +480,7 @@ class << self
465480 # @option options [Array<String>] :aliases (nil)
466481 # @option options [Symbol] :extension (nil)
467482 # @option options [Array<Symbol>] :extensions (nil)
483+ # @option options [URI] :uri (nil)
468484 # @return [void]
469485 #
470486 # @overload content_type
@@ -504,6 +520,10 @@ def self.content_type(type = nil, options = {})
504520 @@content_types [ aa ] << self unless @@content_types [ aa ] . include? ( self )
505521 end
506522 end
523+ # URI identifying this format
524+ if uri = options [ :uri ]
525+ @@uris [ RDF ::URI ( uri ) ] = self
526+ end
507527 end
508528 end
509529
@@ -517,7 +537,7 @@ def self.accept_type
517537 end
518538
519539 ##
520- # Retrieves or defines file extensions for this RDF serialization format.
540+ # Retrieves file extensions for this RDF serialization format.
521541 #
522542 # The return is an array where the first element is the cannonical
523543 # file extension for the format and following elements are alias file extensions.
@@ -527,6 +547,17 @@ def self.file_extension
527547 @@file_extensions . map { |ext , formats | ext if formats . include? ( self ) } . compact
528548 end
529549
550+ ##
551+ # Retrieves any format URI defined for this format..
552+ #
553+ # @return [URI]
554+ def self . uri
555+ @@uris . invert [ self ]
556+ end
557+ class << self
558+ alias_method :to_uri , :uri
559+ end
560+
530561 protected
531562
532563 ##
@@ -568,6 +599,7 @@ def self.content_encoding(encoding = nil)
568599 @@readers = { } # @private
569600 @@writers = { } # @private
570601 @@subclasses = [ ] # @private
602+ @@uris = { } # @private
571603
572604 ##
573605 # @private
0 commit comments