Sha256: fe3bd1269b13e9b9fd378a4ae816fe93003d5ed1ecff0331b5b174758b3a080c

Contents?: true

Size: 979 Bytes

Versions: 5

Compression:

Stored size: 979 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

      def potential_match?(other)
        other == content
      end
    end # Token
  end # GRXML
end # RubySpeech

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby_speech-1.1.0 lib/ruby_speech/grxml/token.rb
ruby_speech-1.0.2 lib/ruby_speech/grxml/token.rb
ruby_speech-1.0.1 lib/ruby_speech/grxml/token.rb
ruby_speech-1.0.0 lib/ruby_speech/grxml/token.rb
ruby_speech-0.5.1 lib/ruby_speech/grxml/token.rb