Class: Pocketsphinx::Grammar::Jsgf
- Inherits:
-
Object
- Object
- Pocketsphinx::Grammar::Jsgf
- Defined in:
- lib/pocketsphinx/grammar/jsgf.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #grammar_from_block(&block) ⇒ Object
- #grammar_from_file(path) ⇒ Object
-
#initialize(path = nil, &block) ⇒ Jsgf
constructor
A new instance of Jsgf.
Constructor Details
#initialize(path = nil, &block) ⇒ Jsgf
Returns a new instance of Jsgf.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pocketsphinx/grammar/jsgf.rb', line 6 def initialize(path = nil, &block) if path.nil? && !block_given? raise "Either a path or block is required to create a JSGF grammar" end if block_given? @raw = grammar_from_block(&block) else @raw = grammar_from_file(path) check_grammar end end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw
4 5 6 |
# File 'lib/pocketsphinx/grammar/jsgf.rb', line 4 def raw @raw end |
Instance Method Details
#grammar_from_block(&block) ⇒ Object
23 24 25 26 27 |
# File 'lib/pocketsphinx/grammar/jsgf.rb', line 23 def grammar_from_block(&block) builder = JsgfBuilder.new builder.instance_eval(&block) builder.jsgf end |
#grammar_from_file(path) ⇒ Object
19 20 21 |
# File 'lib/pocketsphinx/grammar/jsgf.rb', line 19 def grammar_from_file(path) File.read path end |