Class: Lutaml::Xml::CustomMethodWrapper::ElementWrapper
- Inherits:
-
Object
- Object
- Lutaml::Xml::CustomMethodWrapper::ElementWrapper
- Defined in:
- lib/lutaml/xml/transformation/custom_method_wrapper.rb
Overview
Wrapper for XmlDataModel::XmlElement that adds compatibility methods expected by custom serialization methods
Instance Method Summary collapse
-
#add_text(_self, text, cdata: false) ⇒ Object
Add text content to the element (old adapter API).
-
#create_and_add_element(name, attributes: {}) {|ElementWrapper| ... } ⇒ XmlElement
Create and add a child element (old adapter API).
-
#initialize(element, parent_wrapper = nil) ⇒ ElementWrapper
constructor
A new instance of ElementWrapper.
Constructor Details
#initialize(element, parent_wrapper = nil) ⇒ ElementWrapper
Returns a new instance of ElementWrapper.
189 190 191 192 |
# File 'lib/lutaml/xml/transformation/custom_method_wrapper.rb', line 189 def initialize(element, parent_wrapper = nil) @element = element @parent_wrapper = parent_wrapper end |
Instance Method Details
#add_text(_self, text, cdata: false) ⇒ Object
Add text content to the element (old adapter API)
199 200 201 202 203 |
# File 'lib/lutaml/xml/transformation/custom_method_wrapper.rb', line 199 def add_text(_self, text, cdata: false) use_cdata = cdata.is_a?(Hash) ? cdata[:cdata] || false : cdata @element.text_content = text @element.cdata = use_cdata end |
#create_and_add_element(name, attributes: {}) {|ElementWrapper| ... } ⇒ XmlElement
Create and add a child element (old adapter API)
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/lutaml/xml/transformation/custom_method_wrapper.rb', line 211 def create_and_add_element(name, attributes: {}) child = CustomMethodWrapper.build_element(name, attributes) @element.add_child(child) if block_given? yield ElementWrapper.new(child, @parent_wrapper) end child end |