Class: RubySpeech::GRXML::Rule

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

Overview

A rule definition associates a legal rule expansion with a rulename. The rule definition is also responsible for defining the scope of the rule definition: whether it is local to the grammar in which it is defined or whether it may be referenced within other grammars.

http://www.w3.org/TR/speech-grammar/#S3
http://www.w3.org/TR/speech-grammar/#S3.1

The rule element has two attributes: id and scope. The id attribute is always required; the scope is optional.

The id must be unique with-in the grammar document

The scope is either “private” or “public”. If it is not explicitly declared in a rule definition then the scope defaults to “private”.

Constant Summary collapse

VALID_CHILD_TYPES =
[Nokogiri::XML::Element, Nokogiri::XML::Text, String, OneOf, Item, Ruleref, Tag, Token].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, #regexp_content, root_element, #to_doc

Methods included from RubySpeech::GenericElement

#+, #==, #base_uri, #base_uri=, #build, #children, #clone, #create_node, #embed, #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:



73
74
75
76
# File 'lib/ruby_speech/grxml/rule.rb', line 73

def <<(arg)
  raise InvalidChildError, "A Rule can only accept OneOf, Item, Ruleref, Tag, or Token as children" unless VALID_CHILD_TYPES.include? arg.class
  super
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/ruby_speech/grxml/rule.rb', line 78

def eql?(o)
  super o, :id, :scope, :language
end

#idString

The id attribute is the unique name to identify the rule

Returns:

  • (String)


41
42
43
# File 'lib/ruby_speech/grxml/rule.rb', line 41

def id
  read_attr :id, :to_sym
end

#id=(ia) ⇒ Object

Parameters:

  • ia (String)


48
49
50
# File 'lib/ruby_speech/grxml/rule.rb', line 48

def id=(ia)
  self[:id] = ia
end

#scopeString

The scope attribute is optional…

Returns:

  • (String)


58
59
60
# File 'lib/ruby_speech/grxml/rule.rb', line 58

def scope
  read_attr :scope, :to_sym
end

#scope=(sc) ⇒ Object

The scope attribute should only be “private” or “public”

Parameters:

  • ia (String)

Raises:

  • (ArgumentError)


68
69
70
71
# File 'lib/ruby_speech/grxml/rule.rb', line 68

def scope=(sc)
  raise ArgumentError, "A Rule's scope can only be 'public' or 'private'" unless %w{public private}.include?(sc.to_s)
  self[:scope] = sc
end