Class: RubySpeech::NLSML::Document

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

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Document

Returns a new instance of Document.


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

def initialize(xml)
  result = xml.respond_to?(:root) ? xml.root : xml
  unless result.namespace
    result.default_namespace = NLSML_NAMESPACE
    result = Nokogiri::XML.parse(xml.to_xml, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).root
  end
  super result
end

Instance Method Details

#==(other) ⇒ Object


33
34
35
# File 'lib/ruby_speech/nlsml/document.rb', line 33

def ==(other)
  to_xml == other.to_xml
end

#best_interpretationObject


25
26
27
# File 'lib/ruby_speech/nlsml/document.rb', line 25

def best_interpretation
  interpretation_hash_for_interpretation interpretation_nodes.first
end

#grammarObject


15
16
17
# File 'lib/ruby_speech/nlsml/document.rb', line 15

def grammar
  self['grammar']
end

#interpretationsObject


19
20
21
22
23
# File 'lib/ruby_speech/nlsml/document.rb', line 19

def interpretations
  interpretation_nodes.map do |interpretation|
    interpretation_hash_for_interpretation interpretation
  end
end

#match?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/ruby_speech/nlsml/document.rb', line 29

def match?
  interpretation_nodes.count > 0 && !nomatch? && !noinput?
end

#noinput?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'lib/ruby_speech/nlsml/document.rb', line 37

def noinput?
  noinput_elements.any?
end

#to_xmlObject


41
42
43
# File 'lib/ruby_speech/nlsml/document.rb', line 41

def to_xml
  document.to_xml
end