class YARSPG::Format

YARS-PG format specification.

@example Obtaining an ## format class

RDF::Format.for("etc/foaf.yarspg")
RDF::Format.for(file_name:      "etc/foaf.yarspg")
RDF::Format.for(file_extension: "yarspg")
RDF::Format.for(content_type:   "text/yarspg")

@example Obtaining serialization format MIME types

RDF::Format.content_types      #=> {"text/yarspg" => [YARSPG::Format]}

@example Obtaining serialization format file extension mappings

RDF::Format.file_extensions    #=> {yarspg: "text/yarspg"}

@see www.w3.org/TR/rdf-testcases/#ntriples

Public Class Methods

detect(sample) click to toggle source

Sample detection to see if it matches YARS-PG

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.

@param [String] sample Beginning several bytes (~ 1K) of input. @return [Boolean]

# File lib/yarspg/format.rb, line 33
def self.detect(sample)
  !!sample.match(%r(
    (?:%(METADATA|NODE SCHEMAS|EDGE SCHEMAS|NODES|EDGES)) | # Section Names
    (?:[S\{.*\}]-)                                        | # Node Schema
    (?:[S\(.*\)]-)                                        | # Edge Schema
    (?:\(.*\)-)                                             # Edge
  )mx)
end