Class: Yarr::Command::URLEvaluate

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

Overview

evaluates the content fetched from a url on an online evaluator 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, fetch_service: Typhoeus, evaluator_service: EvaluatorService.new) ⇒ URLEvaluate

Returns a new instance of URLEvaluate.

Parameters:

  • fetch_service (#get) (defaults to: Typhoeus)

    A web service that can get

  • evaluator_service (Yarr::EvaluatorService) (defaults to: EvaluatorService.new)

    the evaluator

See Also:

  • for the rest of the arguments

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

def initialize(ast:,
               irc: NoIRC,
               fetch_service: Typhoeus,
               evaluator_service: EvaluatorService.new)
  super(ast: ast, irc: irc)

  @fetch_service = fetch_service
  @evaluator_service = evaluator_service
end

Class Method Details

.match?(ast) ⇒ True|False

Returns can this command handle the AST?.

Parameters:

  • ast (AST)

    parsed ast

Returns:

  • (True|False)

    can this command handle the AST?


14
15
16
# File 'lib/yarr/command/url_evaluate.rb', line 14

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

Instance Method Details

#handleObject

Runs the command


32
33
34
35
36
37
38
39
40
41
# File 'lib/yarr/command/url_evaluate.rb', line 32

def handle
  user_content = @fetch_service.get(url)
  response_code = user_content.response_code
  unless response_code == 200
    return "Request returned response code #{response_code}"
  end

  evaluator_request = EvaluatorService::Request.new(user_content.body)
  @evaluator_service.request(evaluator_request).output
end