lib/yaml_ld/format.rb in yaml-ld-0.0.1 vs lib/yaml_ld/format.rb in yaml-ld-0.0.2

- old
+ new

@@ -1,7 +1,9 @@ # -*- encoding: utf-8 -*- # frozen_string_literal: true +require 'json/ld/format' + module YAML_LD ## # YAML-LD format specification. # # @example Obtaining an YAML-LD format class @@ -26,10 +28,29 @@ content_encoding 'utf-8' reader { YAML_LD::Reader } writer { YAML_LD::Writer } + # 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. + LD_FORMATS = { + 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) + }, + } + } + ## # 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 @@ -52,5 +73,9 @@ def self.name "YAML-LD" end end end + + +# Load into JSON::LD::Format::LD_FORMATS +::JSON::LD::Format.const_get(:LD_FORMATS).merge!(::YAML_LD::Format::LD_FORMATS)