Class: Bandwidth::Bxml::Verb

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

Instance Method Summary collapse

Constructor Details

#initialize(tag, content = nil, attributes = {}) ⇒ Verb

Initializer

Parameters:

  • tag (String)

    Name of the XML element.

  • content (String) (defaults to: nil)

    XML element content. Defaults to nil.

  • attributes (Hash) (defaults to: {})

    The attributes to add to the element. Defaults to an empty hash.



10
11
12
13
14
# File 'lib/bandwidth-sdk/models/bxml/verb.rb', line 10

def initialize(tag, content = nil, attributes = {})
  @tag = tag
  @content = content
  @attributes = attributes
end

Instance Method Details

#generate_xmlNode

Generate an XML element for the verb

Returns:

  • (Node)

    The XML element.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bandwidth-sdk/models/bxml/verb.rb', line 24

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

#set_attributes(attributes) ⇒ Object

Set XML attributes for the verb

Parameters:

  • attributes (Hash)

    The attributes to add to the element.



18
19
20
# File 'lib/bandwidth-sdk/models/bxml/verb.rb', line 18

def set_attributes(attributes)
  @attributes = attributes
end

#to_bxmlString

Return BXML representaion of this element

Returns:

  • (String)

    The XML element in string format.



45
46
47
# File 'lib/bandwidth-sdk/models/bxml/verb.rb', line 45

def to_bxml
  Ox.dump(generate_xml)
end