Class: Wolfram::Query
- Inherits:
-
Object
- Object
- Wolfram::Query
- Defined in:
- lib/wolfram/query.rb
Overview
When given an input, appid and other query params, creates a Result object
Instance Attribute Summary collapse
-
#appid ⇒ Object
Returns the value of attribute appid.
-
#input ⇒ Object
Returns the value of attribute input.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query_uri ⇒ Object
Returns the value of attribute query_uri.
Class Method Summary collapse
Instance Method Summary collapse
-
#fetch ⇒ Object
explicitly fetch the result.
-
#initialize(input, options = {}) ⇒ Query
constructor
A new instance of Query.
- #inspect ⇒ Object
- #params ⇒ Object
- #result ⇒ Object
-
#uri(hash = params) ⇒ Object
the uri that this query will issue a get request to.
Constructor Details
#initialize(input, options = {}) ⇒ Query
Returns a new instance of Query.
11 12 13 14 15 16 |
# File 'lib/wolfram/query.rb', line 11 def initialize(input, = {}) @input = input @appid = .delete(:appid) || Wolfram.appid || raise("No APPID set") @query_uri = .delete(:query_uri) || Wolfram.query_uri @options = end |
Instance Attribute Details
#appid ⇒ Object
Returns the value of attribute appid.
10 11 12 |
# File 'lib/wolfram/query.rb', line 10 def appid @appid end |
#input ⇒ Object
Returns the value of attribute input.
10 11 12 |
# File 'lib/wolfram/query.rb', line 10 def input @input end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/wolfram/query.rb', line 10 def @options end |
#query_uri ⇒ Object
Returns the value of attribute query_uri.
10 11 12 |
# File 'lib/wolfram/query.rb', line 10 def query_uri @query_uri end |
Class Method Details
.fetch(uri) ⇒ Object
6 7 8 |
# File 'lib/wolfram/query.rb', line 6 def self.fetch(uri) open(uri).read end |
Instance Method Details
#fetch ⇒ Object
explicitly fetch the result
19 20 21 |
# File 'lib/wolfram/query.rb', line 19 def fetch @result = Result.new(self.class.fetch(uri), :query => self) end |
#inspect ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/wolfram/query.rb', line 36 def inspect out = "q: \"#{input}\"" out << " #{[:podstate]}" if [:podstate] out << " (assuming #{[:assumption]})" if [:assumption] out << ", a: #{result.datatypes}" if @result out end |
#params ⇒ Object
32 33 34 |
# File 'lib/wolfram/query.rb', line 32 def params .merge(:input => input, :appid => appid) end |
#result ⇒ Object
23 24 25 |
# File 'lib/wolfram/query.rb', line 23 def result @result ||= fetch end |