Class: Saxerator::Builder::XmlBuilder
- Inherits:
-
Object
- Object
- Saxerator::Builder::XmlBuilder
- Defined in:
- lib/saxerator/builder/xml_builder.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_node(node) ⇒ Object
- #block_variable ⇒ Object
-
#initialize(config, name, attributes) ⇒ XmlBuilder
constructor
A new instance of XmlBuilder.
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(config, name, attributes) ⇒ XmlBuilder
Returns a new instance of XmlBuilder.
8 9 10 11 12 13 14 |
# File 'lib/saxerator/builder/xml_builder.rb', line 8 def initialize(config, name, attributes) @config = config @name = name @attributes = attributes @children = [] @text = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/saxerator/builder/xml_builder.rb', line 6 def name @name end |
Instance Method Details
#add_node(node) ⇒ Object
16 17 18 19 |
# File 'lib/saxerator/builder/xml_builder.rb', line 16 def add_node(node) @text = true if node.is_a? String @children << node end |
#block_variable ⇒ Object
32 33 34 35 36 37 |
# File 'lib/saxerator/builder/xml_builder.rb', line 32 def block_variable builder = REXML::Document.new builder << REXML::XMLDecl.new('1.0', 'UTF-8') to_xml(builder) builder end |
#to_xml(builder) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/saxerator/builder/xml_builder.rb', line 21 def to_xml(builder) element = REXML::Element.new(name, nil, attribute_quote: :quote) element.add_attributes(@attributes) if @text element.add_text(@children.join) else @children.each { |child| child.to_xml(element) } end builder.elements << element end |