Class: RubySpeech::NLSML::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_speech/nlsml/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Builder

Returns a new instance of Builder.


6
7
8
9
10
11
12
13
14
# File 'lib/ruby_speech/nlsml/builder.rb', line 6

def initialize(options = {}, &block)
  options = {'xmlns' => NLSML_NAMESPACE}.merge(options)
  xml_doc = Nokogiri::XML::Builder.new do |builder|
    builder.result options do |r|
      apply_block r, &block
    end
  end.doc
  @document = RubySpeech::NLSML::Document.new xml_doc
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object


23
24
25
# File 'lib/ruby_speech/nlsml/builder.rb', line 23

def method_missing(method_name, *args, &block)
  @result.send method_name, *args, &block
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document


4
5
6
# File 'lib/ruby_speech/nlsml/builder.rb', line 4

def document
  @document
end

Instance Method Details

#interpretation(*args, &block) ⇒ Object


16
17
18
19
20
21
# File 'lib/ruby_speech/nlsml/builder.rb', line 16

def interpretation(*args, &block)
  if args.last.respond_to?(:has_key?) && args.last.has_key?(:confidence)
    args.last[:confidence] = args.last[:confidence].to_f
  end
  @result.send :interpretation, *args, &block
end