Class: WolframAlpha
- Inherits:
-
Cogibara::OperatorBase
- Object
- Cogibara::OperatorBase
- WolframAlpha
- Defined in:
- lib/cogibara/operators/wolfram_alpha.rb
Instance Attribute Summary
Attributes inherited from Cogibara::OperatorBase
#clientID, #message_structure, #message_text, #operator_config
Instance Method Summary collapse
Methods inherited from Cogibara::OperatorBase
#confirm, #initialize, #process_file, #receive_message, #say
Constructor Details
This class inherits a constructor from Cogibara::OperatorBase
Instance Method Details
#initialize_operator ⇒ Object
5 6 7 |
# File 'lib/cogibara/operators/wolfram_alpha.rb', line 5 def initialize_operator Wolfram.appid = self.operator_config["API_KEY"] end |
#process(message) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/cogibara/operators/wolfram_alpha.rb', line 19 def process() # puts "asking wolfram #{query}" query = .text result = resultToString(Wolfram.fetch(query)) # puts result == "Result:\n" # result == "Result:\n" ? nil : result end |
#resultToString(result) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/cogibara/operators/wolfram_alpha.rb', line 9 def resultToString(result) rhash = Wolfram::HashPresenter.new(result).to_hash rarr = [] rhash[:pods].keys.each do |key| value = rhash[:pods][key][0] rarr << (key + ":\n\t" + value + "\n") end rarr.join end |