Sha256: e22c814d3b5f0b1ae30896dd7f97c7237c0b41315e014867a6f9cdbb0882ea64
Contents?: true
Size: 1.62 KB
Versions: 3
Compression:
Stored size: 1.62 KB
Contents
require 'libxml' module Twilio module TwiML class TwiMLError < StandardError end # TwiML Base Class class TwiML # Generate getter/setter methods attr_accessor :name attr_accessor :indent def initialize(indent: false, **keyword_args) @name = self.class.name.split('::').last @indent = indent @value = nil @verbs = [] @attrs = {} keyword_args.each do |key, val| @attrs[TwiML.to_lower_camel_case(key)] = val unless val.nil? end end def self.to_lower_camel_case(symbol) # Symbols don't have the .split method, so convert to string first result = symbol.to_s.split('_').map(&:capitalize).join result[0].downcase + result[1..result.length] end def to_s(xml_declaration = true) xml = self.xml.to_s(indent: indent) return ('<?xml version="1.0" encoding="UTF-8"?>' + xml) if xml_declaration xml end alias to_xml to_s def xml # create XML element elem = LibXML::XML::Node.new(@name, @value) # set element attributes keys = @attrs.keys.sort keys.each do |key| value = @attrs[key] value_is_boolean = value.is_a?(TrueClass) || value.is_a?(FalseClass) elem[key] = value_is_boolean ? value.to_s.downcase : value.to_s end @verbs.each do |verb| elem << verb.xml end elem end def append(verb) raise TwiMLError, 'Only appending of TwiML is allowed' unless verb.is_a?(TwiML) @verbs << verb self end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
twilio-ruby-5.2.0 | lib/twilio-ruby/twiml/twiml.rb |
twilio-ruby-5.1.2 | lib/twilio-ruby/twiml/twiml.rb |
twilio-ruby-5.1.1 | lib/twilio-ruby/twiml/twiml.rb |