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.



197
198
199
200
# File 'lib/lutaml/xml/transformation/custom_method_wrapper.rb', line 197

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)



207
208
209
210
211
# File 'lib/lutaml/xml/transformation/custom_method_wrapper.rb', line 207

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:



219
220
221
222
223
224
225
226
227
228
# File 'lib/lutaml/xml/transformation/custom_method_wrapper.rb', line 219

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