Class: AlpacaBuildTool::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/alpacabuildtool/entities/xml.rb

Overview

Xml represents simple xml document with one root node

doc = Xml.new '1.0' do
  node 'a', 'b'
end
doc.to_s
# => <?xml version="1.0"?>
#    <a>b</a>

Instance Method Summary collapse

Constructor Details

#initialize(version, &block) ⇒ Xml

Creates instance

version

xml version

accepts &block


19
20
21
22
# File 'lib/alpacabuildtool/entities/xml.rb', line 19

def initialize(version, &block)
  @version, @root_node = version, nil
  instance_eval(&block) if block_given?
end

Instance Method Details

#node(name, content = nil, &block) ⇒ Object

Set/override root node

name

node name

content

node content

accepts &block


30
31
32
# File 'lib/alpacabuildtool/entities/xml.rb', line 30

def node(name, content = nil, &block)
  @root = XmlNode.new(name, content, &block)
end

#to_sObject

Overrides string representation to generate xml document content from stored objects


37
38
39
# File 'lib/alpacabuildtool/entities/xml.rb', line 37

def to_s
  "<?xml version=\"#{@version}\"?>\n#{@root}"
end