lib/lutaml/model/xml_adapter/nokogiri_adapter.rb in lutaml-model-0.3.4 vs lib/lutaml/model/xml_adapter/nokogiri_adapter.rb in lutaml-model-0.3.5
- old
+ new
@@ -69,14 +69,18 @@
elsif !value.nil? || element_rule.render_nil?
add_to_xml(nsp_xml, value, attribute_def, element_rule)
end
end
- if xml_mapping.content_mapping
- text = element.send(xml_mapping.content_mapping.to)
+ if (content_rule = xml_mapping.content_mapping)
+ text = element.send(content_rule.to)
text = text.join if text.is_a?(Array)
+ if content_rule.custom_methods[:to]
+ text = @root.send(content_rule.custom_methods[:to], @root, text)
+ end
+
prefixed_xml.text text
end
end
end
@@ -128,9 +132,13 @@
end
end
end
def add_to_xml(xml, value, attribute, rule)
+ if rule.custom_methods[:to]
+ value = @root.send(rule.custom_methods[:to], @root, value)
+ end
+
if value && (attribute&.type&.<= Lutaml::Model::Serialize)
handle_nested_elements(
xml,
value,
rule: rule,