class Vines::StanzaError

Constants

KINDS
NAMESPACE
TYPES

Public Class Methods

new(el, type, text=nil) click to toggle source
# File lib/vines/error.rb, line 60
def initialize(el, type, text=nil)
  raise "type must be one of: %s"   % TYPES.join(', ') unless TYPES.include?(type)
  raise "stanza must be one of: %s" % KINDS.join(', ') unless KINDS.include?(el.name)
  @stanza_kind, @type, @text = el.name, type, text
  @id, @from, @to = %w[id from to].map {|a| el[a] }
end

Public Instance Methods

to_xml() click to toggle source
# File lib/vines/error.rb, line 67
def to_xml
  doc = Document.new
  doc.create_element(@stanza_kind) do |el|
    el['from'] = @to   if @to
    el['id']   = @id   if @id
    el['to']   = @from if @from
    el['type'] = 'error'
    el << doc.create_element('error', 'type' => @type) do |error|
      error << doc.create_element(element_name, 'xmlns' => NAMESPACE)
      if @text
        error << doc.create_element('text', @text, 'xmlns' => NAMESPACE, 'xml:lang' => 'en')
      end
    end
  end.to_xml(:indent => 0).gsub(/\n/, '')
end