Class: Lutaml::Turtle::Transform
- Inherits:
-
Rdf::Transform
- Object
- Model::Transform
- Rdf::Transform
- Lutaml::Turtle::Transform
- Defined in:
- lib/lutaml/turtle/transform.rb
Constant Summary
Constants inherited from Model::Transform
Model::Transform::MAX_CACHE_SIZE
Instance Attribute Summary
Attributes inherited from Model::Transform
Instance Method Summary collapse
- #data_to_model(data, _format, options = {}) ⇒ Object
- #model_to_data(instance, _format, options = {}) ⇒ Object
Methods inherited from Model::Transform
#attributes, cache_size, cached_transform, clear_cache!, data_to_model, #initialize, #model_class, model_to_data
Constructor Details
This class inherits a constructor from Lutaml::Model::Transform
Instance Method Details
#data_to_model(data, _format, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lutaml/turtle/transform.rb', line 27 def data_to_model(data, _format, = {}) require "rdf/turtle" mapping = extract_turtle_mapping() unless mapping&.rdf_subject raise MissingSubjectError, "Turtle mapping requires a subject block" end graph = data.is_a?(RDF::Graph) ? data : Lutaml::Turtle::Adapter.parse(data) attrs = extract_attributes(graph, mapping) build_instance(attrs, ) end |
#model_to_data(instance, _format, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lutaml/turtle/transform.rb', line 8 def model_to_data(instance, _format, = {}) require "rdf/turtle" mapping = extract_turtle_mapping() return "" unless mapping if !mapping.rdf_subject && mapping.rdf_predicates.any? && mapping.rdf_members.empty? raise MissingSubjectError, "Turtle mapping requires a subject block" end graph = build_graph(mapping, instance) return "" if graph.empty? prefixes = build_prefixes(mapping, instance) RDF::Turtle::Writer.buffer(prefixes: prefixes) do |writer| graph.each_statement { |stmt| writer << stmt } end.strip end |