Sha256: 8f2e1b91bf475cde7c42349a16f0e86e5ce8fd0f4ee9ae5ca7bb717d96e427b8

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'ox'

module Bandwidth
  module Bxml
    module Verb
      # Initializer
      # @param tag [String] Name of the XML element.
      # @param content [String] XML element content. Defaults to nil.
      # @param attributes [Hash] The attributes to add to the element. Defaults to an empty hash.
      def initialize(tag, content = nil, attributes = {})
        @tag = tag
        @content = content
        @attributes = attributes
        @attribute_map = []
      end

      # Set XML attributes for the verb
      # @param attributes [Hash] The attributes to add to the element.
      def set_attributes(attributes)
        @attributes = attributes
      end

      # Generate an XML element for the verb
      # @return [Node] The XML element.
      def generate_xml
        root = Ox::Element.new(@tag)
        if @content
          root << @content
        end

        if !@attributes.empty?
          @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

        return root
      end

      # Return BXML representaion of this element
      # @return [String] The XML element in string format.
      def to_bxml
        return Ox.dump(generate_xml)
      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/verb.rb
bandwidth-sdk-11.0.0.pre.beta.1 lib/bandwidth-sdk/models/bxml/verb.rb