Method: CoreLibrary::XmlHelper.add_as_attribute

Defined in:
lib/apimatic-core/utilities/xml_helper.rb

.add_as_attribute(root, name, value, datetime_format: nil) ⇒ Object

Adds the value as an attribute.

Parameters:

  • root (REXML::Element)

    Root element of the XML to add the attribute to.

  • name (string)

    Attribute name.

  • value (string)

    Attribute value.

  • datetime_format (CoreLibrary::DateTimeFormat) (defaults to: nil)

    The format to convert the date time into.



49
50
51
52
53
54
55
# File 'lib/apimatic-core/utilities/xml_helper.rb', line 49

def add_as_attribute(root, name, value, datetime_format: nil)
  return if value.nil?

  value = datetime_to_s(value, datetime_format) if value.instance_of?(DateTime)

  root[name] = value
end