class Hermod::XmlNode
A representation of an XML node with content and attributes.
def initialize(name, value, attributes={})
must be in the list of attributes allowed for the node as
attributes - a Hash of attributes as Symbol -> value pairs. The symbol
value - the node contents as a string.
name - the name of the node as it appears in the XML
building methods and should not be called manually.
Internal: creates a XmlNode. This is used by the XmlSectionBuilder's node
def initialize(name, value, attributes={}) @name = name @value = value @attributes = attributes end
def rename_attributes(lookup_hash)
Returns self so it can be used in a call chain (This may change in
lookup_hash - the hash to use to convert symbols to strings HMRC recognise
hash
Internal: replaces symbol attributes with strings looked up in the provided
def rename_attributes(lookup_hash) attributes.keys.each do |attribute| attributes[lookup_hash.fetch(attribute)] = sanitise_attribute(attributes.delete(attribute)) end self end
def to_xml
version).
without any sanitisation (currently - this may change in a future
Internal: turns the XmlNode into an XML::Node including any attributes
def to_xml if value.respond_to? :to_xml value.to_xml else XML::Node.new(@name, @value).tap do |node| @attributes.each do |attribute_name, attribute_value| node[attribute_name] = attribute_value if attribute_value.present? end end end end