Class: Openphar::Transformers::JsonldTransformer
- Inherits:
-
Object
- Object
- Openphar::Transformers::JsonldTransformer
- Defined in:
- lib/openphar/transformers/jsonld_transformer.rb
Overview
Transforms parsed monograph data to JSON-LD format
Instance Attribute Summary collapse
-
#base_iri ⇒ Object
readonly
Returns the value of attribute base_iri.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(context: nil, base_iri: nil) ⇒ JsonldTransformer
constructor
A new instance of JsonldTransformer.
-
#transform(monograph_data, publisher: nil, edition: nil) ⇒ Object
Transform a monograph hash to JSON-LD.
-
#transform_graph(monographs_data, publisher: nil, edition: nil) ⇒ Object
Transform multiple monographs to a JSON-LD graph.
Constructor Details
#initialize(context: nil, base_iri: nil) ⇒ JsonldTransformer
Returns a new instance of JsonldTransformer.
11 12 13 14 |
# File 'lib/openphar/transformers/jsonld_transformer.rb', line 11 def initialize(context: nil, base_iri: nil) @context = context || default_context @base_iri = base_iri || Openphar.base_iri end |
Instance Attribute Details
#base_iri ⇒ Object (readonly)
Returns the value of attribute base_iri.
9 10 11 |
# File 'lib/openphar/transformers/jsonld_transformer.rb', line 9 def base_iri @base_iri end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/openphar/transformers/jsonld_transformer.rb', line 9 def context @context end |
Instance Method Details
#transform(monograph_data, publisher: nil, edition: nil) ⇒ Object
Transform a monograph hash to JSON-LD
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/openphar/transformers/jsonld_transformer.rb', line 17 def transform(monograph_data, publisher: nil, edition: nil) { "@context" => context, "@id" => monograph_iri(monograph_data[:id], publisher), "@type" => monograph_type(monograph_data), "prefLabel" => build_labels(monograph_data), "monographId" => monograph_data[:id], "publisher" => publisher_iri(publisher), "belongsToEdition" => edition_iri(edition), "definition" => { "en" => monograph_data[:definition] }, "testSpecification" => build_test_specifications(monograph_data) }.compact end |
#transform_graph(monographs_data, publisher: nil, edition: nil) ⇒ Object
Transform multiple monographs to a JSON-LD graph
32 33 34 35 36 37 38 39 |
# File 'lib/openphar/transformers/jsonld_transformer.rb', line 32 def transform_graph(monographs_data, publisher: nil, edition: nil) { "@context" => context, "@graph" => monographs_data.map do |data| transform(data, publisher: publisher, edition: edition) end } end |