Module: RubySpeech::GRXML::Builtins
- Defined in:
- lib/ruby_speech/grxml/builtins.rb
Class Method Summary collapse
-
.boolean(options = {}) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a boolean response, where 1 is true and two is false.
-
.currency(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a monetary value.
-
.date(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a date.
-
.digits(options = {}) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a string of digits.
-
.number(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a numeric value.
-
.phone(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a phone number.
-
.time(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a time.
Class Method Details
.boolean(options = {}) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a boolean response, where 1 is true and two is false.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 13 def self.boolean( = {}) truthy_digit = ([:y] || ['y'] || '1').to_s falsy_digit = ([:n] || ['n'] || '2').to_s raise ArgumentError, "Yes and no values cannot be the same" if truthy_digit == falsy_digit RubySpeech::GRXML.draw mode: :dtmf, root: 'boolean' do rule id: 'boolean', scope: 'public' do one_of do item do tag { 'true' } truthy_digit end item do tag { 'false' } falsy_digit end end end end end |
.currency(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a monetary value. Uses ‘*’ as the decimal point. Matches any number of digits, optionally followed by a ‘*’ and up to two more digits.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 91 def self.currency( = nil) RubySpeech::GRXML.draw mode: :dtmf, root: 'currency' do rule id: 'currency', scope: 'public' do item repeat: '0-' do ruleref uri: '#digit' end item repeat: '0-1' do item { '*' } item repeat: '0-2' do ruleref uri: '#digit' end end end rule id: 'digit' do one_of do 0.upto(9) { |d| item { d.to_s } } end end end end |
.date(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a date.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 40 def self.date( = nil) RubySpeech::GRXML.draw mode: :dtmf, root: 'date' do rule id: 'date', scope: 'public' do item repeat: '8' do one_of do 0.upto(9) { |d| item { d.to_s } } end end end end end |
.digits(options = {}) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a string of digits.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 65 def self.digits( = {}) raise ArgumentError, "Cannot specify both absolute length and a length range" if [:length] && ([:minlength] || [:maxlength]) minlength = [:minlength] || ['minlength'] || 0 maxlength = [:maxlength] || ['maxlength'] length = [:length] || ['length'] repeat = length ? length : "#{minlength}-#{maxlength}" RubySpeech::GRXML.draw mode: :dtmf, root: 'digits' do rule id: 'digits', scope: 'public' do item repeat: repeat do one_of do 0.upto(9) { |d| item { d.to_s } } end end end end end |
.number(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a numeric value. Uses ‘*’ as the decimal point. Matches any number of digits, optionally followed by a ‘*’ and any number more digits.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 119 def self.number( = nil) RubySpeech::GRXML.draw mode: :dtmf, root: 'number' do rule id: 'number', scope: 'public' do one_of do item { ruleref uri: '#less_than_one' } item { ruleref uri: '#one_or_more' } end end rule id: 'less_than_one' do item { '*' } item { ruleref uri: '#digit_series' } end rule id: 'one_or_more' do item { ruleref uri: '#digit_series' } item repeat: '0-1' do item { '*' } item(repeat: '0-1') { ruleref uri: '#digit_series' } end end rule(id: 'digit_series') { item(repeat: '1-') { ruleref uri: '#digit' } } rule(id: 'digit') { one_of { 0.upto(9) { |d| item { d.to_s } } } } end end |
.phone(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a phone number. Uses ‘*’ to represent ‘x’ for a number with an extension.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 152 def self.phone( = nil) RubySpeech::GRXML.draw mode: :dtmf, root: 'number' do rule id: 'number', scope: 'public' do item repeat: '1-' do ruleref uri: '#digit' end item repeat: '0-1' do item { '*' } item repeat: '0-' do ruleref uri: '#digit' end end end rule id: 'digit' do one_of do 0.upto(9) { |d| item { d.to_s } } end end end end |
.time(options = nil) ⇒ RubySpeech::GRXML::Grammar
Create a grammar for interpreting a time.
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/ruby_speech/grxml/builtins.rb', line 179 def self.time( = nil) RubySpeech::GRXML.draw mode: :dtmf, root: 'time' do rule id: 'time', scope: 'public' do item repeat: '1-4' do one_of do 0.upto(9) { |d| item { d.to_s } } end end end end end |