Sha256: 0875bb48d836c03577ce9c9fe76c195dbfef30c14488530072c26fcfd4c46569

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

require 'ox'

module Bandwidth
  module Bxml
    class 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
      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? && !@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

      # Return BXML representaion of this element
      # @return [String] The XML element in string format.
      def to_bxml
        Ox.dump(generate_xml)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
bandwidth-sdk-13.1.4 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-13.1.3 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-13.1.2 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-13.1.1 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-13.1.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-13.0.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-12.1.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.3.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.2.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.1.1 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.1.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.0.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.0.0.pre.beta.4.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.0.0.pre.beta.3.1 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.0.0.pre.beta.3.0 lib/bandwidth-sdk/models/bxml/verb.rb
bandwidth-sdk-11.0.0.pre.beta.2.0 lib/bandwidth-sdk/models/bxml/verb.rb