Class: JSON::LD::Format

Inherits:
RDF::Format
  • Object
show all
Defined in:
lib/json/ld/format.rb

Overview

RDFa format specification.

Examples:

Obtaining an Notation3 format class

RDF::Format.for(:json)            #=> JSON::LD::Format
RDF::Format.for(:ld)              #=> JSON::LD::Format
RDF::Format.for("etc/foaf.json")
RDF::Format.for("etc/foaf.ld")
RDF::Format.for(:file_name      => "etc/foaf.json")
RDF::Format.for(:file_name      => "etc/foaf.ld")
RDF::Format.for(file_extension: "json")
RDF::Format.for(file_extension: "ld")
RDF::Format.for(:content_type   => "application/json")

Obtaining serialization format MIME types

RDF::Format.content_types      #=> {"application/json" => [JSON::LD::Format]}

Obtaining serialization format file extension mappings

RDF::Format.file_extensions    #=> {json: "application/json"}

See Also:

Class Method Summary collapse

Class Method Details

.detect(sample) ⇒ Boolean

Sample detection to see if it matches JSON-LD

Use a text sample to detect the format of an input file. Sub-classes implement a matcher sufficient to detect probably format matches, including disambiguating between other similar formats.

Parameters:

  • sample (String)

    Beginning several bytes (~ 1K) of input.

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/json/ld/format.rb', line 41

def self.detect(sample)
  !!sample.match(/\{\s*"@(id|context|type)"/m) &&
    # Exclude CSVW metadata
    !sample.include?("http://www.w3.org/ns/csvw")
end

.nameObject

Override normal format name



55
56
57
# File 'lib/json/ld/format.rb', line 55

def self.name
  "JSON-LD"
end

.to_symObject

Override normal symbol generation



49
50
51
# File 'lib/json/ld/format.rb', line 49

def self.to_sym
  :jsonld
end