Skip to content

Commit

Permalink
[FEATURE] Allow easy access to a GRXML grammar's root rule element
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Dec 20, 2011
1 parent 8c7d515 commit 7e0e9a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ruby_speech/grxml/grammar.rb
Expand Up @@ -110,6 +110,10 @@ def tag_format=(s)
write_attr :'tag-format', s
end

def root_rule
children(:rule, :id => root).first
end

def +(other)
self.class.new(:base_uri => base_uri).tap do |new_grammar|
(self.children + other.children).each do |child|
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby_speech/grxml/grammar_spec.rb
Expand Up @@ -151,6 +151,16 @@ module GRXML
concat.to_s.should_not include('default')
end
end

it "should allow finding its root rule" do
grammar = GRXML::Grammar.new :root => 'foo'
bar = GRXML::Rule.new :id => 'bar'
grammar << bar
foo = GRXML::Rule.new :id => 'foo'
grammar << foo

grammar.root_rule.should == foo
end
end # Grammar
end # GRXML
end # RubySpeech

0 comments on commit 7e0e9a5

Please sign in to comment.