Class: Bandwidth::Bxml::Root

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

Direct Known Subclasses

Bxml, Response

Instance Method Summary collapse

Constructor Details

#initialize(tag, nested_verbs = []) ⇒ Root

Initializer

Parameters:

  • tag (String)

    Name of the XML element.

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

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



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

def initialize(tag, nested_verbs = [])
  @tag = tag
  @nested_verbs = Array(nested_verbs)
end

Instance Method Details

#add_verbs(nested_verbs) ⇒ Object

Add a verb or verbs to the nested verbs array

Parameters:

  • *nested_verbs (Verb)

    or [Array<Verb>] Verb or verbs to add to the array.



35
36
37
# File 'lib/bandwidth-sdk/models/bxml/root.rb', line 35

def add_verbs(nested_verbs)
  @nested_verbs.push(*nested_verbs)
end

#generate_xmlDocument

Generate an XML element for the BXML response

Returns:

  • (Document)

    The XML element.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bandwidth-sdk/models/bxml/root.rb', line 19

def generate_xml
  xml = Ox::Document.new
  instruct = Ox::Instruct.new(:xml)
  instruct[:version] = '1.0'
  instruct[:encoding] = 'UTF-8'
  xml << instruct
  root = Ox::Element.new(@tag)
  @nested_verbs.each do |verb|
    root << verb.generate_xml
  end
  xml << root
  xml
end

#to_bxmlString

Return BXML representaion of this response

Returns:

  • (String)

    The XML response in string format.



41
42
43
44
# File 'lib/bandwidth-sdk/models/bxml/root.rb', line 41

def to_bxml
  bxml = Ox.dump(generate_xml)
  bxml.gsub(SPEAK_SENTENCE_REGEX) { |text| text.gsub(SSML_REGEX, '<\1>') }
end