class Plivo::XML::Prosody

Constants

VALID_PITCH_ATTRIBUTE_VALUES
VALID_RATE_ATTRIBUTE_VALUES
VALID_VOLUME_ATTRIBUTE_VALUES

Public Class Methods

new(body, attributes = {}) click to toggle source
Calls superclass method Plivo::XML::Element::new
# File lib/plivo/xml/prosody.rb, line 11
def initialize(body, attributes = {})
  if attributes.nil? || attributes.length == 0
    raise PlivoXMLError, 'Specify at least one attribute for Prosody tag'
  end
  if attributes[:volume] && !VALID_VOLUME_ATTRIBUTE_VALUES.include?(attributes[:volume]) && !attributes[:volume].include?('dB')
    raise PlivoXMLError, "invalid attribute value #{attributes[:volume]} for volume"
  end
  if attributes[:rate] && !VALID_RATE_ATTRIBUTE_VALUES.include?(attributes[:rate]) && (!attributes[:rate].include?('%') || attributes[:rate].split('%')[0].to_i < 0)
    raise PlivoXMLError, "invalid attribute value #{attributes[:rate]} for rate"
  end
  if attributes[:pitch] && !VALID_PITCH_ATTRIBUTE_VALUES.include?(attributes[:pitch]) && !attributes[:pitch].include?('%')
    raise PlivoXMLError, "invalid attribute value #{attributes[:pitch]} for pitch"
  end
  super(body, attributes)
end