Class: Plivo::XML::SayAs

Inherits:
Element show all
Defined in:
lib/plivo/xml/say_as.rb

Constant Summary collapse

VALID_INTERPRET_AS_ATTRIBUTE_VALUES =
%w(characters spell-out cardinal number ordinal digits fraction unit date time address expletive telephone)
VALID_FORMAT_ATTRIBUTE_VALUES =
%w(mdy dmy ymd md dm ym my d m y yyyymmdd)

Constants inherited from Element

Element::SSML_TAGS

Instance Attribute Summary

Attributes inherited from Element

#name, #node

Instance Method Summary collapse

Methods inherited from Element

#add, #add_attribute, #convert_value, #hyphenate, #method_missing, #to_s, #to_xml

Constructor Details

#initialize(body, attributes = {}) ⇒ SayAs

Returns a new instance of SayAs.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/plivo/xml/say_as.rb', line 10

def initialize(body, attributes = {})
  unless attributes && attributes["interpret-as"]
    raise PlivoXMLError, 'interpret-as is a required attribute for say-as element'
  end
  if !VALID_INTERPRET_AS_ATTRIBUTE_VALUES.include?(attributes["interpret-as"])
    raise PlivoXMLError, "invalid attribute value #{attributes["interpret-as"]} for interpret-as"
  end
  if attributes["interpret-as"]=='date' && attributes[:format] && !VALID_FORMAT_ATTRIBUTE_VALUES.include?(attributes[:format])
    raise PlivoXMLError, "invalid attribute value #{attributes[:format]} for format"
  end
  super(body, attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plivo::XML::Element