Sha256: 256496915b376969f97a734645ed94cc6c13f798390a38d1331ed566e7636004
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
require 'ox' module Bandwidth module Bxml SPEAK_SENTENCE_REGEX = /<SpeakSentence.*?>(.*?)<\/SpeakSentence>/ SSML_REGEX = /<([a-zA-Z\/\/].*?)>/ module Root # Initializer # @param tag [String] Name of the XML element. # @param nested_verbs [Array<Verb>] XML element children. Defaults to an empty array. def initialize(tag, nested_verbs = []) @tag = tag @nested_verbs = nested_verbs end # Generate an XML element for the BXML response # @return [Document] The XML element. 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 return xml end # Add a verb to the nested verbs array # @param *nested_verbs [Verb] or [Array<Verb>] Verb or verbs to add to the array. def add_verb(nested_verbs) @nested_verbs.push(*nested_verbs) end # Return BXML representaion of this response # @return [String] The XML response in string format. def to_bxml bxml = Ox.dump(generate_xml) return bxml.gsub(SPEAK_SENTENCE_REGEX) { |text| text.gsub(SSML_REGEX, '<\1>')} end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bandwidth-sdk-11.0.0.pre.beta.1.1 | lib/bandwidth-sdk/models/bxml/root.rb |
bandwidth-sdk-11.0.0.pre.beta.1 | lib/bandwidth-sdk/models/bxml/root.rb |