Class: Bandwidth::Bxml::NestableVerb

Inherits:
Verb
  • Object
show all
Defined in:
lib/bandwidth-sdk/models/bxml/nestable_verb.rb

Direct Known Subclasses

Gather, StartStream, StartTranscription, Transfer

Instance Method Summary collapse

Methods inherited from Verb

#set_attributes, #to_bxml

Constructor Details

#initialize(tag, content = nil, nested_verbs = [], attributes = {}) ⇒ NestableVerb

Initializer

Parameters:

  • tag (String)

    Name of the XML element.

  • content (String) (defaults to: nil)

    XML element content. Defaults to nil.

  • nested_verbs (Verb) (defaults to: [])

    or [Array<Verb>] XML element children. Defaults to an empty array.

  • attributes (Hash) (defaults to: {})

    The attributes to add to the element. Defaults to an empty hash.



11
12
13
14
15
16
# File 'lib/bandwidth-sdk/models/bxml/nestable_verb.rb', line 11

def initialize(tag, content = nil, nested_verbs = [], attributes = {})
  @tag = tag
  @content = content
  @nested_verbs = Array(nested_verbs)
  @attributes = attributes
end

Instance Method Details

#generate_xmlNode

Generate an XML element for the verb

Returns:

  • (Node)

    The XML element.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bandwidth-sdk/models/bxml/nestable_verb.rb', line 20

def generate_xml
  root = Ox::Element.new(@tag)
  if @content
    root << @content
  end

  if @nested_verbs.length > 0
    @nested_verbs.each do |verb|
      root << verb.generate_xml
    end
  end

  if !@attributes.empty? && !@attribute_map.nil?
    @attributes.each do |key, value|
      if @attribute_map.include? key.to_sym
        root[@attribute_map[key.to_sym]] = value
      else
        raise NoMethodError.new("attribute '#{key}' is not a valid attribute for this verb")
      end
    end
  end

  root
end