Sha256: e32194138e4313585d41724e0af2991cea5485db773e87a44e0fbf5e910f0a7c

Contents?: true

Size: 909 Bytes

Versions: 9

Compression:

Stored size: 909 Bytes

Contents

module RubySpeech
  module GRXML
    ##
    #
    # A token (a.k.a. a terminal symbol) is the part of a grammar that defines words or other entities that may be spoken. Any legal token is a legal expansion.
    #
    #   http://www.w3.org/TR/speech-grammar/#S2.1
    #
    #  The token element may include an optional xml:lang attribute to indicate the language of the contained token.
    #
    class Token < Element

      register :token

      VALID_CHILD_TYPES = [Nokogiri::XML::Element, Nokogiri::XML::Text, String].freeze

      def <<(arg)
        raise InvalidChildError, "A Token can only accept Strings as children" unless VALID_CHILD_TYPES.include? arg.class
        super
      end

      def normalize_whitespace
        self.content = content.strip.squeeze ' '
      end

      def regexp_content # :nodoc:
        Regexp.escape content
      end
    end # Token
  end # GRXML
end # RubySpeech

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby_speech-2.1.2-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.1.2 lib/ruby_speech/grxml/token.rb
ruby_speech-2.1.1-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.1.1 lib/ruby_speech/grxml/token.rb
ruby_speech-2.1.0-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.1.0 lib/ruby_speech/grxml/token.rb
ruby_speech-2.0.2 lib/ruby_speech/grxml/token.rb
ruby_speech-2.0.1 lib/ruby_speech/grxml/token.rb
ruby_speech-0.5.0 lib/ruby_speech/grxml/token.rb