ruby_speech 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/ruby_speech.rb +8 -4
- data/lib/ruby_speech/generic_element.rb +17 -7
- data/lib/ruby_speech/grxml.rb +13 -9
- data/lib/ruby_speech/grxml/grammar.rb +1 -1
- data/lib/ruby_speech/grxml/item.rb +1 -1
- data/lib/ruby_speech/grxml/one_of.rb +0 -4
- data/lib/ruby_speech/grxml/token.rb +0 -4
- data/lib/ruby_speech/ssml.rb +13 -9
- data/lib/ruby_speech/ssml/speak.rb +1 -1
- data/lib/ruby_speech/version.rb +1 -1
- data/lib/ruby_speech/xml.rb +5 -1
- data/spec/ruby_speech/grxml_spec.rb +15 -0
- data/spec/ruby_speech/ssml_spec.rb +13 -0
- metadata +21 -21
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 0.3.4
|
2
|
+
* Eager-autoload all elements so that importing will work with elements that havn't been used yet directly
|
3
|
+
* Allow using the DSL with method calls out of the block
|
4
|
+
* Fix inspection/comparison of some elements that don't have a language attribute
|
5
|
+
|
1
6
|
# 0.3.3
|
2
7
|
* Allow `SSML::Element.import` and `GRXML::Element.import` to take a string as well as a Nokogiri::XML::Node
|
3
8
|
* Allow importing GRXML/SSML documents via their respective modules (eg `RubySpeech::GRXML.import '<grammar ... />'`)
|
data/lib/ruby_speech.rb
CHANGED
@@ -10,8 +10,12 @@ module RubySpeech
|
|
10
10
|
|
11
11
|
autoload :Version
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
eager_autoload do
|
14
|
+
autoload :GenericElement
|
15
|
+
autoload :SSML
|
16
|
+
autoload :GRXML
|
17
|
+
autoload :XML
|
18
|
+
end
|
17
19
|
end
|
20
|
+
|
21
|
+
ActiveSupport::Autoload.eager_autoload!
|
@@ -54,7 +54,7 @@ module RubySpeech
|
|
54
54
|
def new(element_name, atts = {}, &block)
|
55
55
|
blk_proc = lambda do |new_node|
|
56
56
|
atts.each_pair { |k, v| new_node.send :"#{k}=", v }
|
57
|
-
block_return = new_node.
|
57
|
+
block_return = new_node.eval_dsl_block &block
|
58
58
|
new_node << new_node.encode_special_chars(block_return) if block_return.is_a?(String)
|
59
59
|
end
|
60
60
|
|
@@ -71,6 +71,12 @@ module RubySpeech
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
def eval_dsl_block(&block)
|
75
|
+
return unless block_given?
|
76
|
+
@block_binding = eval "self", block.binding
|
77
|
+
instance_eval &block
|
78
|
+
end
|
79
|
+
|
74
80
|
def children
|
75
81
|
super.map { |c| self.class.import c }
|
76
82
|
end
|
@@ -92,13 +98,17 @@ module RubySpeech
|
|
92
98
|
|
93
99
|
def method_missing(method_name, *args, &block)
|
94
100
|
const_name = method_name.to_s.sub('ssml', '').titleize.gsub(' ', '')
|
95
|
-
|
96
|
-
|
97
|
-
if const
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
+
if self.class.module.const_defined? const_name
|
102
|
+
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
|
101
109
|
end
|
110
|
+
elsif @block_binding# && @block_binding.respond_to?(method_name)
|
111
|
+
@block_binding.send method_name, *args, &block
|
102
112
|
else
|
103
113
|
super
|
104
114
|
end
|
data/lib/ruby_speech/grxml.rb
CHANGED
@@ -2,14 +2,16 @@ module RubySpeech
|
|
2
2
|
module GRXML
|
3
3
|
extend ActiveSupport::Autoload
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
eager_autoload do
|
6
|
+
autoload :Element
|
7
|
+
autoload :Grammar
|
8
|
+
autoload :Rule
|
9
|
+
autoload :Item
|
10
|
+
autoload :OneOf
|
11
|
+
autoload :Ruleref
|
12
|
+
autoload :Tag
|
13
|
+
autoload :Token
|
14
|
+
end
|
13
15
|
|
14
16
|
InvalidChildError = Class.new StandardError
|
15
17
|
|
@@ -17,7 +19,7 @@ module RubySpeech
|
|
17
19
|
|
18
20
|
def self.draw(attributes = {}, &block)
|
19
21
|
Grammar.new(attributes).tap do |grammar|
|
20
|
-
block_return = grammar.
|
22
|
+
block_return = grammar.eval_dsl_block &block
|
21
23
|
grammar << block_return if block_return.is_a?(String)
|
22
24
|
end
|
23
25
|
end
|
@@ -27,3 +29,5 @@ module RubySpeech
|
|
27
29
|
end
|
28
30
|
end # GRXML
|
29
31
|
end # RubySpeech
|
32
|
+
|
33
|
+
ActiveSupport::Autoload.eager_autoload!
|
data/lib/ruby_speech/ssml.rb
CHANGED
@@ -2,14 +2,16 @@ module RubySpeech
|
|
2
2
|
module SSML
|
3
3
|
extend ActiveSupport::Autoload
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
eager_autoload do
|
6
|
+
autoload :Audio
|
7
|
+
autoload :Break
|
8
|
+
autoload :Element
|
9
|
+
autoload :Emphasis
|
10
|
+
autoload :Prosody
|
11
|
+
autoload :SayAs
|
12
|
+
autoload :Speak
|
13
|
+
autoload :Voice
|
14
|
+
end
|
13
15
|
|
14
16
|
InvalidChildError = Class.new StandardError
|
15
17
|
|
@@ -17,7 +19,7 @@ module RubySpeech
|
|
17
19
|
|
18
20
|
def self.draw(&block)
|
19
21
|
Speak.new.tap do |speak|
|
20
|
-
block_return = speak.
|
22
|
+
block_return = speak.eval_dsl_block &block
|
21
23
|
speak << block_return if block_return.is_a?(String)
|
22
24
|
end
|
23
25
|
end
|
@@ -27,3 +29,5 @@ module RubySpeech
|
|
27
29
|
end
|
28
30
|
end # SSML
|
29
31
|
end # RubySpeech
|
32
|
+
|
33
|
+
ActiveSupport::Autoload.eager_autoload!
|
data/lib/ruby_speech/version.rb
CHANGED
data/lib/ruby_speech/xml.rb
CHANGED
@@ -28,6 +28,21 @@ module RubySpeech
|
|
28
28
|
doc.should == expected_doc
|
29
29
|
end
|
30
30
|
|
31
|
+
it "should allow accessing methods defined outside the block" do
|
32
|
+
def foo
|
33
|
+
'bar'
|
34
|
+
end
|
35
|
+
|
36
|
+
doc = GRXML.draw do
|
37
|
+
rule :id => foo
|
38
|
+
end
|
39
|
+
|
40
|
+
expected_doc = GRXML::Grammar.new
|
41
|
+
rule = GRXML::Rule.new(:id => foo)
|
42
|
+
expected_doc << rule
|
43
|
+
doc.should == expected_doc
|
44
|
+
end
|
45
|
+
|
31
46
|
it "should raise error if given an empty rule" do
|
32
47
|
pending 'Reject empty rules -- http://www.w3.org/TR/2002/CR-speech-grammar-20020626/#S3.1 http://www.w3.org/Voice/2003/srgs-ir/test/rule-no-empty.grxml'
|
33
48
|
lambda { GRXML.draw { rule :id => 'main' }}.should raise_error
|
@@ -56,6 +56,19 @@ module RubySpeech
|
|
56
56
|
doc.should == expected_doc
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should allow accessing methods defined outside the block" do
|
60
|
+
def foo
|
61
|
+
'bar'
|
62
|
+
end
|
63
|
+
|
64
|
+
doc = SSML.draw do
|
65
|
+
string foo
|
66
|
+
end
|
67
|
+
|
68
|
+
expected_doc = SSML::Speak.new :content => foo
|
69
|
+
doc.should == expected_doc
|
70
|
+
end
|
71
|
+
|
59
72
|
describe "embedding" do
|
60
73
|
it "SSML documents" do
|
61
74
|
doc1 = RubySpeech::SSML.draw do
|
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
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: niceogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156730280 !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: *
|
24
|
+
version_requirements: *2156730280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156729680 !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: *
|
35
|
+
version_requirements: *2156729680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156728960 !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: *
|
46
|
+
version_requirements: *2156728960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156728320 !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: *
|
57
|
+
version_requirements: *2156728320
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: ci_reporter
|
60
|
-
requirement: &
|
60
|
+
requirement: &2156727580 !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: *
|
68
|
+
version_requirements: *2156727580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &2156726900 !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: *
|
79
|
+
version_requirements: *2156726900
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &2156726240 !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: *
|
90
|
+
version_requirements: *2156726240
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: mocha
|
93
|
-
requirement: &
|
93
|
+
requirement: &2156725500 !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: *
|
101
|
+
version_requirements: *2156725500
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: i18n
|
104
|
-
requirement: &
|
104
|
+
requirement: &2156724880 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2156724880
|
113
113
|
description: Prepare SSML and GRXML documents with ease
|
114
114
|
email:
|
115
115
|
- ben@langfeld.me
|
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
segments:
|
188
188
|
- 0
|
189
|
-
hash: -
|
189
|
+
hash: -1285553440311979925
|
190
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
191
|
none: false
|
192
192
|
requirements:
|
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
195
|
version: '0'
|
196
196
|
segments:
|
197
197
|
- 0
|
198
|
-
hash: -
|
198
|
+
hash: -1285553440311979925
|
199
199
|
requirements: []
|
200
200
|
rubyforge_project: ruby_speech
|
201
201
|
rubygems_version: 1.8.10
|