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.
6 7 8 9 10 11 12 |
# File 'lib/saxerator/builder/xml_builder.rb', line 6 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.
4 5 6 |
# File 'lib/saxerator/builder/xml_builder.rb', line 4 def name @name end |
Instance Method Details
#add_node(node) ⇒ Object
14 15 16 17 |
# File 'lib/saxerator/builder/xml_builder.rb', line 14 def add_node(node) @text = true if node.is_a? String @children << node end |
#block_variable ⇒ Object
29 30 31 32 33 |
# File 'lib/saxerator/builder/xml_builder.rb', line 29 def block_variable builder = Nokogiri::XML::Builder.new to_xml(builder) builder.doc end |
#to_xml(builder) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/saxerator/builder/xml_builder.rb', line 19 def to_xml(builder) if @text builder.send("#{name}_", @attributes, @children.join) else builder.send("#{name}_", @attributes) do |xml| @children.each { |child| child.to_xml(xml) } end end end |