ruby-eval-in 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2dd0fb8faca5158abd3038c2d915d17b2c518c8
4
- data.tar.gz: 36f65bbd9a0dd28609f5c24ab6a5a428f94ad004
3
+ metadata.gz: 73f75c21a90cfa0edbce574ce269414b66684172
4
+ data.tar.gz: 3003813f791edcf17e8d07916b4b9a4693ef76b6
5
5
  SHA512:
6
- metadata.gz: 845bf9ae9e01bd0bfad71eaf941fd3902440b1c405a83e4df5ff4ef6dc0aec08c754b1a7102b7c660e498e392f01d4a66870214864502d50cfe17d1aa0ee6972
7
- data.tar.gz: 455eda3895c3c0d5c1f7fee34f1f7f66a68a786a07d2465e0fb708aefc5dd0f767e4070351b77f12f49c5128f9b18edd0f00210bceafdc0387f46fe8f9cad224
6
+ metadata.gz: db4cdb798b4281821df3c2e2a44173b2b732876a966c9cb1c116a364f538c79449d8a2d7d096122e7dbe0a54852a1696339226fa7dc9c77bbbcfd85b6952eeaa
7
+ data.tar.gz: 8d607751ea5bc26659587e0c3729b3423a94b16116de5316e93fbf5a47b67600774d18bd5d6154b806708674f6655666c4f03c0026935a055849d2d2713fff92
@@ -1,21 +1,22 @@
1
- # eval-in.rb
2
- # Author: William Woodruff
3
- # A Ruby interface to the eval.in (https://eval.in) service.
1
+ # frozen_string_literal: true
4
2
 
5
- require "eval-in/result"
6
- require "eval-in/exceptions"
3
+ require_relative "eval-in/result"
4
+ require_relative "eval-in/exceptions"
7
5
 
8
6
  # The primary namespace.
9
7
  # @author William Woodruff
10
8
  # @since 0.0.1
11
9
  module EvalIn
12
- # Evaluate some code in a given language.
13
- # @example
14
- # EvalIn.eval(:ruby, 'puts "Hello, World"') # => #<EvalIn::Result:0xNN>
15
- # @param [Symbol, String] lang the language to execute in
16
- # @param [String] code the program code to execute
17
- # @return [EvalIn::Result] the execution results
18
- def self.eval(lang, code)
19
- EvalIn::Result.new(lang.to_s.downcase, code)
20
- end
10
+ # The library's current version.
11
+ VERSION = "0.0.5"
12
+
13
+ # Evaluate some code in a given language.
14
+ # @example
15
+ # EvalIn.eval(:ruby, 'puts "Hello, World"') # => #<EvalIn::Result:0xNN>
16
+ # @param [Symbol, String] lang the language to execute in
17
+ # @param [String] code the program code to execute
18
+ # @return [EvalIn::Result] the execution results
19
+ def self.eval(lang, code)
20
+ EvalIn::Result.new(lang.to_s.downcase, code)
21
+ end
21
22
  end
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EvalIn
2
- # A parent Error class for all eval-in errors.
3
- class EvalInError < RuntimeError
4
- end
4
+ # A parent Error class for all eval-in errors.
5
+ class EvalInError < RuntimeError
6
+ end
5
7
 
6
- # Raised when an error occurs during connection.
7
- class ConnectionError < EvalInError
8
- def initialize(error)
9
- super "Connection error: #{error.to_s}"
10
- end
11
- end
8
+ # Raised when an error occurs during connection.
9
+ class ConnectionError < EvalInError
10
+ def initialize(error)
11
+ super "Connection error: #{error}"
12
+ end
13
+ end
12
14
 
13
- # Raised when EvalIn.{EvalIn.eval} is given a bad input language.
14
- class BadLanguageError < EvalInError
15
- def initialize(lang)
16
- super "No such language: #{lang}"
17
- end
18
- end
15
+ # Raised when EvalIn.{EvalIn.eval} is given a bad input language.
16
+ class BadLanguageError < EvalInError
17
+ def initialize(lang)
18
+ super "No such language: #{lang}"
19
+ end
20
+ end
19
21
 
20
- # Raised when EvalIn.{EvalIn.eval} is given blank or whitespace-only code.
21
- class EmptyCodeError < EvalInError
22
- def initialize
23
- super "The code may not be empty"
24
- end
25
- end
22
+ # Raised when EvalIn.{EvalIn.eval} is given blank or whitespace-only code.
23
+ class EmptyCodeError < EvalInError
24
+ def initialize
25
+ super "The code may not be empty"
26
+ end
27
+ end
26
28
  end
@@ -1,89 +1,82 @@
1
- require 'nokogiri'
2
- require 'net/http'
3
- require 'uri'
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+ require "net/http"
5
+ require "uri"
4
6
 
5
7
  module EvalIn
6
- # A representation of a result produced by an eval.in query.
7
- class Result
8
- # @private
9
- URL = URI("https://eval.in")
8
+ # A representation of a result produced by an eval.in query.
9
+ class Result
10
+ # @private
11
+ URL = URI("https://eval.in")
10
12
 
11
- # The languages supported by eval.in.
12
- # Any of these keys or values will work for the lang parameter in
13
- # {EvalIn.eval}.
14
- LANGS = {
15
- "c" => "c/gcc-4.9.1",
16
- "c++" => "c++/gcc-4.9.1",
17
- "coffeescript" => "coffeescript/node-0.10.29-coffee-1.7.1",
18
- "fortran" => "fortran/f95-4.4.3",
19
- "haskell" => "haskell/hugs98-sep-2006",
20
- "io" => "io/io-20131204",
21
- "js" => "javascript/node-0.10.29",
22
- "lua" => "lua/lua-5.2.3",
23
- "ocaml" => "ocaml/ocaml-4.01.0",
24
- "php" => "php/php-5.5.14",
25
- "pascal" => "pascal/fpc-2.6.4",
26
- "perl" => "perl/perl-5.20.0",
27
- "python" => "python/cpython-3.4.1",
28
- "python2" => "python/cpython-2.7.8",
29
- "ruby" => "ruby/mri-2.2",
30
- "slash" => "slash/slash-head",
31
- "nasm" => "assembly/nasm-2.07"
32
- }
13
+ # The languages supported by eval.in.
14
+ # Any of these keys or values will work for the lang parameter in
15
+ # {EvalIn.eval}.
16
+ LANGS = {
17
+ "c" => "c/gcc-4.9.1",
18
+ "c++" => "c++/gcc-4.9.1",
19
+ "coffeescript" => "coffeescript/node-0.10.29-coffee-1.7.1",
20
+ "fortran" => "fortran/f95-4.4.3",
21
+ "haskell" => "haskell/hugs98-sep-2006",
22
+ "io" => "io/io-20131204",
23
+ "js" => "javascript/node-0.10.29",
24
+ "lua" => "lua/lua-5.2.3",
25
+ "ocaml" => "ocaml/ocaml-4.01.0",
26
+ "php5" => "php/php-5.6.23",
27
+ "php7" => "php/php-7.0.8",
28
+ "pascal" => "pascal/fpc-2.6.4",
29
+ "perl" => "perl/perl-5.20.0",
30
+ "python" => "python/cpython-3.4.1",
31
+ "python2" => "python/cpython-2.7.8",
32
+ "ruby" => "ruby/mri-2.4",
33
+ "slash" => "slash/slash-head",
34
+ "nasm" => "assembly/nasm-2.07",
35
+ }.freeze
33
36
 
34
- # @return [String] the expanded language used in execution
35
- # @example
36
- # result.language # => "ruby/mri-2.2"
37
- attr_reader :language
37
+ # @return [String] the expanded language used in execution
38
+ # @example
39
+ # result.language # => "ruby/mri-2.2"
40
+ attr_reader :language
38
41
 
39
- # @return [String] the program code used in execution
40
- # @example
41
- # result.code # => "puts \"hello\""
42
- attr_reader :code
42
+ # @return [String] the program code used in execution
43
+ # @example
44
+ # result.code # => "puts \"hello\""
45
+ attr_reader :code
43
46
 
44
- # @return [String] any output produced by the program
45
- # @example
46
- # result.output # => "hello\n"
47
- attr_reader :output
47
+ # @return [String] any output produced by the program
48
+ # @example
49
+ # result.output # => "hello\n"
50
+ attr_reader :output
48
51
 
49
- # @return [String] the program's exit status
50
- # @example
51
- # result.status # => "OK (0 sec real, 0 sec wall, 8 MB, 16 syscalls)"
52
- attr_reader :status
52
+ # @return [String] the program's exit status
53
+ # @example
54
+ # result.status # => "OK (0 sec real, 0 sec wall, 8 MB, 16 syscalls)"
55
+ attr_reader :status
53
56
 
54
- # @return [URI] a permalink to the output webpage
55
- # @example
56
- # result.url # => #<URI::HTTPS https://eval.in/xxxxxx>
57
- attr_reader :url
57
+ # @return [URI] a permalink to the output webpage
58
+ # @example
59
+ # result.url # => #<URI::HTTPS https://eval.in/xxxxxx>
60
+ attr_reader :url
58
61
 
59
- # @private
60
- def initialize(lang, code)
61
- if LANGS.key?(lang)
62
- lang = LANGS[lang]
63
- elsif !LANGS.value?(lang)
64
- raise BadLanguageError.new(lang)
65
- end
62
+ # @private
63
+ def initialize(lang, code)
64
+ if LANGS.key?(lang)
65
+ lang = LANGS[lang]
66
+ elsif !LANGS.value?(lang)
67
+ raise BadLanguageError, lang
68
+ end
66
69
 
67
- raise EmptyCodeError.new if code.strip.empty?
70
+ raise EmptyCodeError if code.strip.empty?
68
71
 
69
- @lang = lang
70
- @code = code
72
+ @lang = lang
73
+ @code = code
71
74
 
72
- result = Net::HTTP.post_form(URL,
73
- "execute" => "on",
74
- "lang" => lang,
75
- "code" => code
76
- )
75
+ result = Net::HTTP.post_form(URL, "execute" => "on", "lang" => lang, "code" => code)
77
76
 
78
- if result.is_a? Net::HTTPFound
79
- @url = URI(result["location"])
77
+ raise ConnectionError, result unless result.is_a? Net::HTTPFound
80
78
 
81
- html = Nokogiri::HTML(Net::HTTP.get(@url))
82
- @output = html.css("pre").last.text
83
- @status = html.css("p")[1].text
84
- else
85
- raise ConnectionError.new(result)
86
- end
87
- end
88
- end
79
+ @url = URI(result["location"])
80
+ end
81
+ end
89
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-eval-in
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-22 00:00:00.000000000 Z
11
+ date: 2017-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.4.5.1
61
+ rubygems_version: 2.6.13
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: ruby-eval-in - A Ruby interface to https://eval.in/.