Class: Yarr::Command::Evaluate

Inherits:
Base
  • Object
show all
Extended by:
Concern::ASTDigger
Defined in:
lib/yarr/command/evaluate.rb

Overview

evaluates the user's message using an online evaluation service like carc.in

Instance Attribute Summary

Attributes inherited from Base

#ast, #irc

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concern::ASTDigger

digger

Constructor Details

#initialize(ast:, irc: NoIRC, web_service: EvaluatorService.new, configuration: Yarr.config) ⇒ Evaluate

Returns a new instance of Evaluate.

See Also:

  • for the rest of the arguments

25
26
27
28
29
30
31
32
33
# File 'lib/yarr/command/evaluate.rb', line 25

def initialize(ast:,
               irc: NoIRC,
               web_service: EvaluatorService.new,
               configuration: Yarr.config)
  super(ast: ast, irc: irc)

  @service = web_service
  @config = configuration.evaluator
end

Class Method Details

.match?(ast) ⇒ True|False


18
19
20
# File 'lib/yarr/command/evaluate.rb', line 18

def self.match?(ast)
  ast.key? :evaluate
end

Instance Method Details

#handleObject

Runs the command


36
37
38
39
40
# File 'lib/yarr/command/evaluate.rb', line 36

def handle
  response =
    @service.request(EvaluatorService::Request.new(code, service_lang))
  respond_with(response)
end