ruby_speech 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ # develop
2
+
3
+ # 0.4.0 - 2011-12-30
4
+ * Feature: Add the ability to look up child elements by name/attributes easily
5
+ * Feature: Allow easy access to a GRXML grammar's root rule element
6
+ * Feature: Allow inlining a Grammar's rulerefs
7
+ * Bugfix: Ruby 1.8 and JRuby don't do a tree-search for const_defined?
8
+ * Bugfix: Don't try to pass a method call up to the DSL block binding if it doesn't respond to the method either
9
+
1
10
  # 0.3.4
2
11
  * Eager-autoload all elements so that importing will work with elements that havn't been used yet directly
3
12
  * Allow using the DSL with method calls out of the block
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2, :cli => '--format documentation' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec/" }
5
+ end
data/README.md CHANGED
@@ -51,9 +51,7 @@ Contruct a GRXML (SRGS) document like this:
51
51
  ```ruby
52
52
  require 'ruby_speech'
53
53
 
54
- grammy = RubySpeech::GRXML.draw do
55
- self.mode = 'dtmf'
56
- self.root = 'digits'
54
+ grammy = RubySpeech::GRXML.draw :mode => 'dtmf', :root => 'digits' do
57
55
  rule id: 'digits' do
58
56
  one_of do
59
57
  0.upto(9) {|d| item { d.to_s } }
@@ -77,14 +77,28 @@ module RubySpeech
77
77
  instance_eval &block
78
78
  end
79
79
 
80
- def children
81
- super.map { |c| self.class.import c }
80
+ def children(type = nil, attributes = nil)
81
+ if type
82
+ expression = type.to_s
83
+
84
+ expression << '[' << attributes.inject([]) do |h, (key, value)|
85
+ h << "@#{key}='#{value}'"
86
+ end.join(',') << ']' if attributes
87
+
88
+ if namespace_href
89
+ find "ns:#{expression}", :ns => namespace_href
90
+ else
91
+ find expression
92
+ end
93
+ else
94
+ super()
95
+ end.map { |c| self.class.import c }
82
96
  end
83
97
 
84
98
  def embed(other)
85
99
  case other
86
100
  when String
87
- self << encode_special_chars(other)
101
+ string other
88
102
  when self.class.root_element
89
103
  other.children.each do |child|
90
104
  self << child
@@ -96,18 +110,16 @@ module RubySpeech
96
110
  end
97
111
  end
98
112
 
113
+ def string(other)
114
+ self << encode_special_chars(other)
115
+ end
116
+
99
117
  def method_missing(method_name, *args, &block)
100
118
  const_name = method_name.to_s.sub('ssml', '').titleize.gsub(' ', '')
101
- if self.class.module.const_defined? const_name
119
+ if self.class.module.const_defined?(const_name)
102
120
  const = self.class.module.const_get const_name
103
- if self.class::VALID_CHILD_TYPES.include?(const)
104
- if const == String
105
- self << encode_special_chars(args.first)
106
- else
107
- self << const.new(*args, &block)
108
- end
109
- end
110
- elsif @block_binding# && @block_binding.respond_to?(method_name)
121
+ self << const.new(*args, &block)
122
+ elsif @block_binding && @block_binding.respond_to?(method_name)
111
123
  @block_binding.send method_name, *args, &block
112
124
  else
113
125
  super
@@ -15,6 +15,8 @@ module RubySpeech
15
15
  GRXML
16
16
  end
17
17
 
18
+ alias_method :nokogiri_children, :children
19
+
18
20
  include GenericElement
19
21
  end # Element
20
22
  end # GRXML
@@ -110,6 +110,22 @@ module RubySpeech
110
110
  write_attr :'tag-format', s
111
111
  end
112
112
 
113
+ def root_rule
114
+ children(:rule, :id => root).first
115
+ end
116
+
117
+ def inline
118
+ find("//ns:ruleref", :ns => namespace_href).each do |ref|
119
+ rule = children(:rule, :id => ref[:uri].sub(/^#/, '')).first
120
+ ref.swap rule.nokogiri_children
121
+ end
122
+
123
+ non_root_rules = xpath "./ns:rule[@id!='#{root}']", :ns => namespace_href
124
+ non_root_rules.remove
125
+
126
+ self
127
+ end
128
+
113
129
  def +(other)
114
130
  self.class.new(:base_uri => base_uri).tap do |new_grammar|
115
131
  (self.children + other.children).each do |child|
@@ -1,3 +1,3 @@
1
1
  module RubySpeech
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -28,4 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency %q<rake>, [">= 0"]
29
29
  s.add_development_dependency %q<mocha>, [">= 0"]
30
30
  s.add_development_dependency %q<i18n>, [">= 0"]
31
+ s.add_development_dependency %q<guard>, [">= 0.9.0"]
32
+ s.add_development_dependency %q<guard-rspec>, [">= 0"]
33
+ s.add_development_dependency %q<ruby_gntp>, [">= 0"]
31
34
  end
@@ -151,6 +151,64 @@ module RubySpeech
151
151
  concat.to_s.should_not include('default')
152
152
  end
153
153
  end
154
+
155
+ it "should allow finding its root rule" do
156
+ grammar = GRXML::Grammar.new :root => 'foo'
157
+ bar = GRXML::Rule.new :id => 'bar'
158
+ grammar << bar
159
+ foo = GRXML::Rule.new :id => 'foo'
160
+ grammar << foo
161
+
162
+ grammar.root_rule.should == foo
163
+ end
164
+
165
+ it "should allow inlining rule references" do
166
+ grammar = GRXML.draw :root => 'pin', :mode => :dtmf do
167
+ rule :id => 'digits' do
168
+ one_of do
169
+ 0.upto(9) { |d| item { d.to_s } }
170
+ end
171
+ end
172
+
173
+ rule :id => 'pin', :scope => 'public' do
174
+ one_of do
175
+ item do
176
+ item :repeat => '4' do
177
+ ruleref :uri => '#digits'
178
+ end
179
+ "#"
180
+ end
181
+ item do
182
+ "* 9"
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ expected_grammar = GRXML.draw :root => 'pin', :mode => :dtmf do
189
+ rule :id => 'pin', :scope => 'public' do
190
+ one_of do
191
+ item do
192
+ item :repeat => '4' do
193
+ one_of do
194
+ 0.upto(9) { |d| item { d.to_s } }
195
+ end
196
+ end
197
+ "#"
198
+ end
199
+ item do
200
+ "* 9"
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+ grammar.inline.should == expected_grammar
207
+ end
208
+
209
+ describe "#tokens" do
210
+ context "with unquoted tokens"
211
+ end
154
212
  end # Grammar
155
213
  end # GRXML
156
214
  end # RubySpeech
@@ -261,6 +261,20 @@ module RubySpeech
261
261
  its(:children) { should == [string,item] }
262
262
  end
263
263
  end
264
+
265
+ it "should allow finding direct children of a particular type, matching certain attributes" do
266
+ item = GRXML::Item.new
267
+ item1 = GRXML::Item.new :weight => 0.5
268
+ item11 = GRXML::Item.new :weight => 0.5
269
+ item1 << item11
270
+ item << item1
271
+ item2 = GRXML::Item.new :weight => 0.7
272
+ item << item2
273
+ tag = GRXML::Tag.new
274
+ item << tag
275
+
276
+ item.children(:item, :weight => 0.5).should == [item1]
277
+ end
264
278
  end # draw
265
279
  end # GRXML
266
280
  end # RubySpeech
@@ -15,13 +15,20 @@ module RubySpeech
15
15
  end
16
16
  end
17
17
 
18
- describe "when the return value of the block is a string" do
18
+ describe "when the return value of the block is not a string" do
19
19
  it "should not be inserted into the document" do
20
20
  expected_doc = SSML::Speak.new
21
21
  SSML.draw { :foo }.should == expected_doc
22
22
  end
23
23
  end
24
24
 
25
+ describe "when inserting a string" do
26
+ it "should work" do
27
+ expected_doc = SSML::Speak.new(:content => "Hi, I'm Fred")
28
+ SSML.draw { string "Hi, I'm Fred" }.should == expected_doc
29
+ end
30
+ end
31
+
25
32
  it "should allow other SSML elements to be inserted in the document" do
26
33
  doc = SSML.draw { voice :gender => :male, :name => 'fred' }
27
34
  expected_doc = SSML::Speak.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000 Z
12
+ date: 2011-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: niceogiri
16
- requirement: &2156730280 !ruby/object:Gem::Requirement
16
+ requirement: &2152682720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156730280
24
+ version_requirements: *2152682720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2156729680 !ruby/object:Gem::Requirement
27
+ requirement: &2152682100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156729680
35
+ version_requirements: *2152682100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2156728960 !ruby/object:Gem::Requirement
38
+ requirement: &2152681560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156728960
46
+ version_requirements: *2152681560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2156728320 !ruby/object:Gem::Requirement
49
+ requirement: &2152681040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.7.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2156728320
57
+ version_requirements: *2152681040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ci_reporter
60
- requirement: &2156727580 !ruby/object:Gem::Requirement
60
+ requirement: &2152680460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2156727580
68
+ version_requirements: *2152680460
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &2156726900 !ruby/object:Gem::Requirement
71
+ requirement: &2152679960 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.7.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2156726900
79
+ version_requirements: *2152679960
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &2156726240 !ruby/object:Gem::Requirement
82
+ requirement: &2152679440 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2156726240
90
+ version_requirements: *2152679440
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mocha
93
- requirement: &2156725500 !ruby/object:Gem::Requirement
93
+ requirement: &2152678860 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2156725500
101
+ version_requirements: *2152678860
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: i18n
104
- requirement: &2156724880 !ruby/object:Gem::Requirement
104
+ requirement: &2152678360 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,40 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2156724880
112
+ version_requirements: *2152678360
113
+ - !ruby/object:Gem::Dependency
114
+ name: guard
115
+ requirement: &2152677860 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: 0.9.0
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *2152677860
124
+ - !ruby/object:Gem::Dependency
125
+ name: guard-rspec
126
+ requirement: &2152677380 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *2152677380
135
+ - !ruby/object:Gem::Dependency
136
+ name: ruby_gntp
137
+ requirement: &2152676820 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *2152676820
113
146
  description: Prepare SSML and GRXML documents with ease
114
147
  email:
115
148
  - ben@langfeld.me
@@ -122,6 +155,7 @@ files:
122
155
  - .travis.yml
123
156
  - CHANGELOG.md
124
157
  - Gemfile
158
+ - Guardfile
125
159
  - LICENSE.md
126
160
  - README.md
127
161
  - Rakefile
@@ -186,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
220
  version: '0'
187
221
  segments:
188
222
  - 0
189
- hash: -1285553440311979925
223
+ hash: -633963194735147828
190
224
  required_rubygems_version: !ruby/object:Gem::Requirement
191
225
  none: false
192
226
  requirements:
@@ -195,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
229
  version: '0'
196
230
  segments:
197
231
  - 0
198
- hash: -1285553440311979925
232
+ hash: -633963194735147828
199
233
  requirements: []
200
234
  rubyforge_project: ruby_speech
201
235
  rubygems_version: 1.8.10