Class: Wolfram::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/wolfram/query.rb

Overview

When given an input, appid and other query params, creates a Result object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @input = input
  @appid = options.delete(:appid) || Wolfram.appid || raise("No APPID set")
  @query_uri = options.delete(:query_uri) || Wolfram.query_uri
  @options = options
end

Instance Attribute Details

#appidObject

Returns the value of attribute appid.



10
11
12
# File 'lib/wolfram/query.rb', line 10

def appid
  @appid
end

#inputObject

Returns the value of attribute input.



10
11
12
# File 'lib/wolfram/query.rb', line 10

def input
  @input
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/wolfram/query.rb', line 10

def options
  @options
end

#query_uriObject

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

#fetchObject

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

#inspectObject



36
37
38
39
40
41
42
# File 'lib/wolfram/query.rb', line 36

def inspect
  out = "q: \"#{input}\""
  out << " #{options[:podstate]}" if options[:podstate]
  out << " (assuming #{options[:assumption]})" if options[:assumption]
  out << ", a: #{result.datatypes}" if @result
  out
end

#paramsObject



32
33
34
# File 'lib/wolfram/query.rb', line 32

def params
  options.merge(:input => input, :appid => appid)
end

#resultObject



23
24
25
# File 'lib/wolfram/query.rb', line 23

def result
  @result ||= fetch
end

#uri(hash = params) ⇒ Object

the uri that this query will issue a get request to



28
29
30
# File 'lib/wolfram/query.rb', line 28

def uri(hash=params)
  "#{query_uri}?#{Util.to_param(hash)}"
end