Class: Lutaml::JsonLd::Adapter

Inherits:
KeyValue::Document show all
Defined in:
lib/lutaml/jsonld/adapter.rb

Instance Attribute Summary

Attributes inherited from KeyValue::Document

#attributes, #register

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from KeyValue::Document

#[], #[]=, #initialize, #key?, #to_h

Constructor Details

This class inherits a constructor from Lutaml::KeyValue::Document

Class Method Details

.parse(jsonld_string, _options = {}) ⇒ Object



9
10
11
# File 'lib/lutaml/jsonld/adapter.rb', line 9

def self.parse(jsonld_string, _options = {})
  JSON.parse(jsonld_string)
end

Instance Method Details

#to_jsonld(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lutaml/jsonld/adapter.rb', line 13

def to_jsonld(*args)
  data = @attributes

  unless Lutaml::Json::GeneratorOptions.lutaml_options?(args.first)
    return JSON.generate(data, args.first)
  end

  options = args.first || {}
  generator_options = Lutaml::Json::GeneratorOptions.filter(options)

  if options[:pretty]
    JSON.pretty_generate(data, generator_options)
  else
    JSON.generate(data, generator_options)
  end
end