Class: Wolfram::Result
- Inherits:
-
Object
- Object
- Wolfram::Result
- Extended by:
- Util
- Includes:
- Enumerable, XmlContainer
- Defined in:
- lib/wolfram/result.rb
Overview
Result of a Query. Can have multiple Assumptions and Pods.
Instance Attribute Summary collapse
-
#assumptions ⇒ Object
readonly
Returns the value of attribute assumptions.
-
#pods ⇒ Object
readonly
Returns the value of attribute pods.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Attributes included from XmlContainer
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#assumption ⇒ Object
shortcut to the first assumption.
- #format ⇒ Object
-
#initialize(xml, options = {}) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
- #success? ⇒ Boolean
- #types ⇒ Object
Methods included from Util
delegate, module_get, to_param, to_query
Methods included from XmlContainer
Constructor Details
#initialize(xml, options = {}) ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 18 19 20 |
# File 'lib/wolfram/result.rb', line 13 def initialize(xml, = {}) @query = [:query] @xml = Nokogiri::XML(xml.to_s).search('queryresult').first @xml or raise MissingNodeError, "<queryresult> node missing from xml: #{xml[0..20]}..." @assumptions = Assumption.collection(@xml, ) @pods = Pod.collection(@xml, ) types.each {|mod| extend mod} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Wolfram::XmlContainer
Instance Attribute Details
#assumptions ⇒ Object (readonly)
Returns the value of attribute assumptions.
11 12 13 |
# File 'lib/wolfram/result.rb', line 11 def assumptions @assumptions end |
#pods ⇒ Object (readonly)
Returns the value of attribute pods.
11 12 13 |
# File 'lib/wolfram/result.rb', line 11 def pods @pods end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
11 12 13 |
# File 'lib/wolfram/result.rb', line 11 def query @query end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 |
# File 'lib/wolfram/result.rb', line 22 def [](key) key.is_a?(String) ? pods.find {|e| e.title == key } : pods[key] end |
#assumption ⇒ Object
shortcut to the first assumption
31 32 33 |
# File 'lib/wolfram/result.rb', line 31 def assumption assumptions[0] end |
#format ⇒ Object
46 47 48 |
# File 'lib/wolfram/result.rb', line 46 def format @query && @query.[:format] end |
#inspect ⇒ Object
39 40 41 42 43 44 |
# File 'lib/wolfram/result.rb', line 39 def inspect out = "a: #{xml['datatypes']}" out << " (assumptions: #{assumptions.map(&:name).join(', ')})" if !Array(assumptions).empty? out << pods.map{|pod| "\n - #{pod.to_s.gsub("\n", "\n ")}"}.join out end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/wolfram/result.rb', line 26 def success? success end |
#types ⇒ Object
35 36 37 |
# File 'lib/wolfram/result.rb', line 35 def types @types ||= xml['datatypes'].split(',').map {|type| Util.module_get(Result, type)} end |