class Aws::Xml::DocBuilder

Attributes

target[R]

Public Class Methods

new(options = {}) click to toggle source

@option options [#<<] :target ('') @option options [String] :pad ('') @option options [String] :indent ('')

# File lib/aws-sdk-core/xml/doc_builder.rb, line 8
def initialize(options = {})
  @target = options[:target] || ''
  @indent = options[:indent] || ''
  @pad = options[:pad] || ''
  @end_of_line = @indent == '' ? '' : "\n"
end

Public Instance Methods

node(name, *args) { || ... } click to toggle source

@overload node(name, attributes = {})

Adds a self closing element without any content.

@overload node(name, value, attributes = {})

Adds an element that opens and closes on the same line with
simple text content.

@overload node(name, attributes = {}, &block)

Adds a wrapping element.  Calling {#node} from inside
the yielded block creates nested elements.

@return [void]

# File lib/aws-sdk-core/xml/doc_builder.rb, line 30
def node(name, *args, &block)
  attrs = args.last.is_a?(Hash) ? args.pop : {}
  if block_given?
    @target << open_el(name, attrs)
    @target << @end_of_line
    increase_pad { yield }
    @target << @pad
    @target << close_el(name)
  elsif args.empty?
    @target << empty_element(name, attrs)
  else
    @target << inline_element(name, args.first, attrs)
  end
end

Private Instance Methods

attributes(attr) click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 67
def attributes(attr)
  if attr.empty?
    ''
  else
    ' ' + attr.map do |key, value|
      "#{key}=#{escape(value, :attr)}"
    end.join(' ')
  end
end
close_el(name) click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 59
def close_el(name)
  "</#{name}>#{@end_of_line}"
end
empty_element(name, attrs) click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 47
def empty_element(name, attrs)
  "#{@pad}<#{name}#{attributes(attrs)}/>#{@end_of_line}"
end
escape(string, text_or_attr) click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 63
def escape(string, text_or_attr)
  string.to_s.encode(:xml => text_or_attr)
end
increase_pad() { || ... } click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 77
def increase_pad(&block)
  pre_increase = @pad
  @pad = @pad + @indent
  yield
  @pad = pre_increase
end
inline_element(name, value, attrs) click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 51
def inline_element(name, value, attrs)
  "#{open_el(name, attrs)}#{escape(value, :text)}#{close_el(name)}"
end
open_el(name, attrs) click to toggle source
# File lib/aws-sdk-core/xml/doc_builder.rb, line 55
def open_el(name, attrs)
  "#{@pad}<#{name}#{attributes(attrs)}>"
end