Sha256: 9a4b3119978a10b860b6c40850ff0bd1c11c4a976afb378f11042dc4fe095e3c

Contents?: true

Size: 981 Bytes

Versions: 3

Compression:

Stored size: 981 Bytes

Contents

module RubySpeech
  module SSML
    class Element < Niceogiri::XML::Node
      def self.new(element_name, atts = {}, &block)
        super(element_name) do |new_node|
          atts.each_pair { |k, v| new_node.send :"#{k}=", v }
          block_return = new_node.instance_eval &block if block_given?
          new_node << new_node.encode_special_chars(block_return) if block_return.is_a?(String)
        end
      end

      def method_missing(method_name, *args, &block)
        const_name = method_name.to_s.sub('ssml', '').titleize.gsub(' ', '')
        const = SSML.const_get const_name
        if const && self.class::VALID_CHILD_TYPES.include?(const)
          if const == String
            self << encode_special_chars(args.first)
          else
            self << const.new(*args, &block)
          end
        else
          super
        end
      end

      def eql?(o, *args)
        super o, :content, *args
      end
    end # Element
  end # SSML
end # RubySpeech

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby_speech-0.1.5 lib/ruby_speech/ssml/element.rb
ruby_speech-0.1.4 lib/ruby_speech/ssml/element.rb
ruby_speech-0.1.3 lib/ruby_speech/ssml/element.rb