Class: Lutaml::Xml::CustomMethodWrapper::ElementWrapper

Inherits:
Object
  • Object
show all
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

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)

Parameters:

  • _self (XmlElement)

    Self parameter (ignored, for compatibility)

  • text (String)

    Text content

  • cdata (Boolean, Hash) (defaults to: false)

    Whether to use CDATA (true or true)



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)

Parameters:

  • name (String)

    Element name

  • attributes (Hash) (defaults to: {})

    Optional attributes to add to the element

Yields:

Returns:



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