Method: RDF::Format.content_type

Defined in:
lib/rdf/format.rb

.content_type(type, options) ⇒ void .content_typeArray<String>

Retrieves or defines MIME content types for this RDF serialization format.

Overloads:

  • .content_type(type, options) ⇒ void

    This method returns an undefined value.

    Retrieves or defines the MIME content type for this RDF serialization format.

    Optionally also defines alias MIME content types for this RDF serialization format.

    Optionally also defines a file extension, or a list of file extensions, that should be mapped to the given MIME type and handled by this class.

    Optionally, both ‘type`, `alias`, and `aliases`, may be parameterized for expressing quality.

    content_type "text/html;q=0.4"
    

    Parameters:

    • type (String)
    • options (Hash{Symbol => Object})

    Options Hash (options):

    • :alias (String) — default: nil
    • :aliases (Array<String>) — default: nil
    • :extension (Symbol) — default: nil
    • :extensions (Array<Symbol>) — default: nil
    • :uri (URI) — default: nil
  • .content_typeArray<String>

    Retrieves the MIME content types for this RDF serialization format.

    The return is an array where the first element is the cannonical MIME type for the format and following elements are alias MIME types.

    Returns:

    • (Array<String>)


497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/rdf/format.rb', line 497

def self.content_type(type = nil, options = {})
  if type.nil?
    [@@content_type[self], @@content_types.map {
      |ct, cl| (cl.include?(self) && ct != @@content_type[self]) ?  ct : nil }].flatten.compact
  else
    accept_type, type = type, type.split(';').first
    @@content_type[self] = type
    @@content_types[type] ||= []
    @@content_types[type] << self unless @@content_types[type].include?(self)

    @@accept_types[accept_type] ||= []
    @@accept_types[accept_type] << self unless @@accept_types[accept_type].include?(self)

    if extensions = (options[:extension] || options[:extensions])
      extensions = Array(extensions).map(&:to_sym)
      extensions.each do |ext|
        @@file_extensions[ext] ||= []
        @@file_extensions[ext] << self unless @@file_extensions[ext].include?(self)
      end
    end
    if aliases = (options[:alias] || options[:aliases])
      aliases = Array(aliases).each do |a|
        aa = a.split(';').first
        @@accept_types[a] ||= []
        @@accept_types[a] << self unless @@accept_types[a].include?(self)

        @@content_types[aa] ||= []
        @@content_types[aa] << self unless @@content_types[aa].include?(self)
      end
    end
    # URI identifying this format
    if uri = options[:uri]
      @@uris[RDF::URI(uri)] = self
    end
  end
end