Class: Pocketsphinx::Grammar::Jsgf

Inherits:
Object
  • Object
show all
Defined in:
lib/pocketsphinx/grammar/jsgf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rawObject (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