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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concern::ASTDigger

digger

Constructor Details

#initialize(ast, web_service = EvaluatorService.new, config = Yarr.config) ⇒ Evaluate

Returns a new instance of Evaluate.

Parameters:

  • web_service (#post) (defaults to: EvaluatorService.new)

    A web client that can post

  • config (Configuration) (defaults to: Yarr.config)

    Configuration loaded


22
23
24
25
26
27
28
29
# File 'lib/yarr/command/evaluate.rb', line 22

def initialize(ast,
               web_service = EvaluatorService.new,
               config = Yarr.config)
  super(ast)

  @service = web_service
  @config = config.evaluator
end

Class Method Details

.match?(ast) ⇒ Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/yarr/command/evaluate.rb', line 16

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

Instance Method Details

#handleObject


31
32
33
34
35
# File 'lib/yarr/command/evaluate.rb', line 31

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