lib/lutaml/lutaml_path/document_wrapper.rb in lutaml-0.2.0 vs lib/lutaml/lutaml_path/document_wrapper.rb in lutaml-0.3.0
- old
+ new
@@ -1,26 +1,40 @@
-require "jmespath"
-
module Lutaml
module LutamlPath
class DocumentWrapper
attr_reader :serialized_document
def initialize(document)
@serialized_document = serialize_document(document)
end
- # Method for traversing document` structure
- # example for lutaml: wrapper.find('//#main-doc/main-class/nested-class')
- # Need to return descendant of Lutaml::LutamlPath::EntryWrapper
- def find(path)
- JMESPath.search(path, serialized_document)
+ def to_liquid
+ serialized_document
end
protected
def serialize_document(_path)
raise ArgumentError, "implement #serialize_document!"
+ end
+
+ def serialize_value(attr_value)
+ if attr_value.is_a?(Array)
+ return attr_value.map(&method(:serialize_to_hash))
+ end
+
+ attr_value
+ end
+
+ def serialize_to_hash(object)
+ object.instance_variables.each_with_object({}) do |var, res|
+ variable = object.instance_variable_get(var)
+ res[var.to_s.gsub("@", "")] = if variable.is_a?(Array)
+ variable.map { |n| serialize_to_hash(n) }
+ else
+ variable
+ end
+ end
end
end
end
end