Class: Lutaml::JsonLd::Transform
- Inherits:
-
Rdf::Transform
- Object
- Model::Transform
- Rdf::Transform
- Lutaml::JsonLd::Transform
- Defined in:
- lib/lutaml/jsonld/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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lutaml/jsonld/transform.rb', line 19 def data_to_model(data, _format, = {}) mapping = extract_mapping() return model_class.new unless mapping hash = data.is_a?(String) ? JSON.parse(data) : data if hash.key?("@graph") && hash["@graph"].is_a?(Array) && !hash["@graph"].empty? graph_data = hash["@graph"] first = graph_data.first hash = first.is_a?(Hash) ? first : {} end hash = strip_jsonld_keywords(hash) attrs = {} mapping.rdf_predicates.each do |rule| value = hash[rule.predicate_name] next if value.nil? attrs[rule.to] = if rule.lang_tagged && value.is_a?(Hash) flatten_language_map(value) else value end end build_instance(attrs, ) end |
#model_to_data(instance, _format, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lutaml/jsonld/transform.rb', line 8 def model_to_data(instance, _format, = {}) mapping = extract_mapping() return {} unless mapping if mapping.rdf_members.any? build_graph_document(mapping, instance) else build_resource_object(mapping, instance) end end |