Class: YAML_LD::Format

Inherits:
RDF::Format show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/yaml-ld-2d2ba8e32d66/lib/yaml_ld/format.rb

Overview

YAML-LD format specification.

Examples:

Obtaining an YAML-LD format class

RDF::Format.for(:yamlld)           #=> YAML_LD::Format
RDF::Format.for("etc/foaf.yamlld")
RDF::Format.for(:file_name         => "etc/foaf.yamlld")
RDF::Format.for(file_extension: "yamlld")
RDF::Format.for(:content_type   => "application/ld+yaml")

Obtaining serialization format MIME types

RDF::Format.content_types      #=> {"application/ld+yaml" => [YAML_LD::Format],

Obtaining serialization format file extension mappings

RDF::Format.file_extensions    #=> {:yamlld => [YAML_LD::Format] }

See Also:

Constant Summary collapse

LD_FORMATS =

Specify how to execute CLI commands for each supported format. These are added to the LD_FORMATS defined for JSON::LD::Format Derived formats (e.g., YAML-LD) define their own entrypoints.

{
  yamlld: {
    expand: ->(input, **options) {
      YAML_LD::API.expand(input, validate: false, **options)
    },
    compact: ->(input, **options) {
      YAML_LD::API.compact(input, options[:context], **options)
    },
    flatten: ->(input, **options) {
      YAML_LD::API.flatten(input, options[:context], **options)
    },
    frame: ->(input, **options) {
      YAML_LD::API.frame(input, options[:frame], **options)
    },
  }
}

Class Method Summary collapse

Methods inherited from RDF::Format

accept_type, accept_types, cli_commands, content_encoding, content_type, content_types, each, file_extension, file_extensions, for, reader, reader_symbols, reader_types, require, symbols, uri, uris, writer, writer_symbols, writer_types

Class Method Details

.detect(sample) ⇒ Boolean

Sample detection to see if it matches YAML-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)


61
62
63
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/yaml-ld-2d2ba8e32d66/lib/yaml_ld/format.rb', line 61

def self.detect(sample)
  !!sample.match(/---/m)
end

.nameObject

Override normal format name



73
74
75
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/yaml-ld-2d2ba8e32d66/lib/yaml_ld/format.rb', line 73

def self.name
  "YAML-LD"
end

.to_symObject

Override normal symbol generation



67
68
69
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/yaml-ld-2d2ba8e32d66/lib/yaml_ld/format.rb', line 67

def self.to_sym
  :yamlld
end