Sha256: 641e9411a8dc0e9162a5587d8e5a13abb1e64c9b06bfb39f9b447fd8c07a22b7

Contents?: true

Size: 973 Bytes

Versions: 18

Compression:

Stored size: 973 Bytes

Contents

require 'ruby_speech/xml/language'

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
      include XML::Language

      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

18 entries across 18 versions & 1 rubygems

Version Path
ruby_speech-3.0.1-java lib/ruby_speech/grxml/token.rb
ruby_speech-3.0.1 lib/ruby_speech/grxml/token.rb
ruby_speech-3.0.0-java lib/ruby_speech/grxml/token.rb
ruby_speech-3.0.0 lib/ruby_speech/grxml/token.rb
ruby_speech-2.4.0-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.4.0 lib/ruby_speech/grxml/token.rb
ruby_speech-2.3.2-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.3.2 lib/ruby_speech/grxml/token.rb
ruby_speech-2.3.1-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.3.1 lib/ruby_speech/grxml/token.rb
ruby_speech-2.3.0-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.3.0 lib/ruby_speech/grxml/token.rb
ruby_speech-2.2.2-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.2.2 lib/ruby_speech/grxml/token.rb
ruby_speech-2.2.1-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.2.1 lib/ruby_speech/grxml/token.rb
ruby_speech-2.2.0-java lib/ruby_speech/grxml/token.rb
ruby_speech-2.2.0 lib/ruby_speech/grxml/token.rb