class EvalIn::Result

A representation of a result produced by an eval.in query.

Constants

LANGS

The languages supported by eval.in. Any of these keys or values will work for the lang parameter in

{EvalIn.eval}.
URL

@private

Attributes

code[R]

@return [String] the program code used in execution @example

result.code # => "puts \"hello\""
language[R]

@return [String] the expanded language used in execution @example

result.language # => "ruby/mri-2.2"
output[R]

@return [String] any output produced by the program @example

result.output # => "hello\n"
status[R]

@return [String] the program's exit status @example

result.status # => "OK (0 sec real, 0 sec wall, 8 MB, 16 syscalls)"
url[R]

@return [URI] a permalink to the output webpage @example

result.url # => #<URI::HTTPS https://eval.in/xxxxxx>

Public Class Methods

new(lang, code) click to toggle source

@private

# File lib/eval-in/result.rb, line 64
def initialize(lang, code)
  if LANGS.key?(lang)
    lang = LANGS[lang]
  elsif !LANGS.value?(lang)
    raise BadLanguageError, lang
  end

  raise EmptyCodeError if code.strip.empty?

  @lang = lang
  @code = code

  result = Net::HTTP.post_form(URL, "execute" => "on", "lang" => lang, "code" => code)

  raise ConnectionError, result unless result.is_a? Net::HTTPFound

  @url = URI(result["location"])
  html = Nokogiri::HTML(Net::HTTP.get(@url))
  @output = html.css("pre").last.text
  @status = html.css("p")[1].text
end