Class: RubySpeech::GRXML::Token

Inherits:
Element
  • Object
show all
Includes:
XML::Language
Defined in:
lib/ruby_speech/grxml/token.rb

Overview

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.

Constant Summary collapse

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

Instance Attribute Summary

Attributes included from RubySpeech::GenericElement

#parent

Instance Method Summary collapse

Methods included from XML::Language

#language, #language=

Methods inherited from Element

module, namespace, root_element, #to_doc

Methods included from RubySpeech::GenericElement

#+, #==, #base_uri, #base_uri=, #build, #children, #clone, #create_node, #embed, #eql?, #eval_dsl_block, included, #inherit, #initialize, #inspect, #mass_assign, #method_missing, #namespace=, #namespace_href, #node, #nokogiri_children, #read_attr, #respond_to_missing?, #string, #to_s, #traverse, #version, #version=, #write_attr

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubySpeech::GenericElement

Instance Method Details

#<<(arg) ⇒ Object

Raises:



20
21
22
23
# File 'lib/ruby_speech/grxml/token.rb', line 20

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

#normalize_whitespaceObject



25
26
27
# File 'lib/ruby_speech/grxml/token.rb', line 25

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

#regexp_contentObject

:nodoc:



29
30
31
# File 'lib/ruby_speech/grxml/token.rb', line 29

def regexp_content # :nodoc:
  Regexp.escape content
end