ruby-eval-in 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/bin/eval-in +13 -0
- data/lib/eval-in.rb +21 -0
- data/lib/eval-in/exceptions.rb +19 -0
- data/lib/eval-in/result.rb +101 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d58e7440ce3e56c5514b8024d7ac3b95be797120
|
4
|
+
data.tar.gz: ecf3c84ba0c003b1a4bd178194a433334c5d5d37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45b7cb744a86ed758e616df02252d46644ed59dbc44cef1e4a67f2782a87456483e115346591ad5b32998630d61d6bb9a9849630da4e9700b716c54852565fde
|
7
|
+
data.tar.gz: 2d23181ff732dca4cf2e5f40879a4a98c65d7ee5c8ed3c4a0c4246c81af0bb43aa63b1c273a1bad8bfe8760deb20e9815f74137678857129b9817f93891f836f
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private --markup-provider=redcarpet --markup=markdown - README.md LICENSE
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 William Woodruff <william @ tuffbizz.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
ruby-eval-in
|
2
|
+
============
|
3
|
+
|
4
|
+
A basic Ruby interface to the [eval.in](https://eval.in) online evaluation
|
5
|
+
service.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
`ruby-eval-in` can be installed as a RubyGem:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ gem install ruby-eval-in
|
13
|
+
```
|
14
|
+
|
15
|
+
## Examples
|
16
|
+
|
17
|
+
Making queries is very simple:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'eval-in'
|
21
|
+
|
22
|
+
result = EvalIn.eval(:ruby, 'puts 10**2')
|
23
|
+
|
24
|
+
result.output # => "100\n"
|
25
|
+
result.status # => "OK (0 sec real, 0 sec wall, 8 MB, 16 syscalls)"
|
26
|
+
result.url # => #<URI::HTTPS https://eval.in/xxxxxx>
|
27
|
+
```
|
28
|
+
|
29
|
+
The provided command line script can also be used:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
$ eval-in ruby 'puts 10**2'
|
33
|
+
# 100
|
34
|
+
```
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
`ruby-eval-in` is licensed under the MIT License.
|
39
|
+
|
40
|
+
See the LICENSE file for more details.
|
data/bin/eval-in
ADDED
data/lib/eval-in.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# eval-in.rb
|
2
|
+
# Author: William Woodruff
|
3
|
+
# A Ruby interface to the eval.in (https://eval.in) service.
|
4
|
+
|
5
|
+
require "eval-in/result"
|
6
|
+
require "eval-in/exceptions"
|
7
|
+
|
8
|
+
# The primary namespace.
|
9
|
+
# @author William Woodruff
|
10
|
+
# @since 0.0.1
|
11
|
+
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
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module EvalIn
|
2
|
+
# A parent Error class for all eval-in errors.
|
3
|
+
class EvalInError < RuntimeError
|
4
|
+
end
|
5
|
+
|
6
|
+
# Raised when EvalIn.{EvalIn.eval} is given a bad input language.
|
7
|
+
class BadLanguageError < EvalInError
|
8
|
+
def initialize(lang)
|
9
|
+
super "No such language: #{lang}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Raised when EvalIn.{EvalIn.eval} is given blank or whitespace-only code.
|
14
|
+
class EmptyCodeError < EvalInError
|
15
|
+
def initialize
|
16
|
+
super "The code may not be empty"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'mechanize'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module EvalIn
|
6
|
+
# A representation of a result produced by an eval.in query.
|
7
|
+
class Result
|
8
|
+
# @private
|
9
|
+
URL = "https://eval.in"
|
10
|
+
|
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
|
+
"ruby" => "ruby/mri-2.2",
|
29
|
+
"slash" => "slash/slash-head",
|
30
|
+
"nasm" => "assembly/nasm-2.07"
|
31
|
+
}
|
32
|
+
|
33
|
+
# @return [String] the expanded language used in execution
|
34
|
+
# @example
|
35
|
+
# result.language # => "ruby/mri-2.2"
|
36
|
+
attr_reader :language
|
37
|
+
|
38
|
+
# @return [String] the program code used in execution
|
39
|
+
# @example
|
40
|
+
# result.code # => "puts \"hello\""
|
41
|
+
attr_reader :code
|
42
|
+
|
43
|
+
# @return [String] any output produced by the program
|
44
|
+
# @example
|
45
|
+
# result.output # => "hello\n"
|
46
|
+
attr_reader :output
|
47
|
+
|
48
|
+
# @return [String] the program's exit status
|
49
|
+
# @example
|
50
|
+
# result.status # => "OK (0 sec real, 0 sec wall, 8 MB, 16 syscalls)"
|
51
|
+
attr_reader :status
|
52
|
+
|
53
|
+
# @return [URI] a permalink to the output webpage
|
54
|
+
# @example
|
55
|
+
# result.url # => #<URI::HTTPS https://eval.in/xxxxxx>
|
56
|
+
attr_reader :url
|
57
|
+
|
58
|
+
# @private
|
59
|
+
def initialize(lang, code)
|
60
|
+
if LANGS.key?(lang)
|
61
|
+
lang = LANGS[lang]
|
62
|
+
elsif !LANGS.value?(lang)
|
63
|
+
raise BadLanguageError.new(lang)
|
64
|
+
end
|
65
|
+
|
66
|
+
raise EmptyCodeError.new if code.strip.empty?
|
67
|
+
|
68
|
+
@lang = lang
|
69
|
+
@code = code
|
70
|
+
@html = get_page
|
71
|
+
@output = get_output
|
72
|
+
@status = get_status
|
73
|
+
@url = get_url
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def get_page
|
79
|
+
mech = Mechanize.new
|
80
|
+
page = mech.get(URL)
|
81
|
+
form = page.forms.first
|
82
|
+
|
83
|
+
form.field_with(:name => "code").value = @code
|
84
|
+
form.field_with(:name => "lang").value = @lang
|
85
|
+
Nokogiri::HTML(mech.submit(form).body)
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_output
|
89
|
+
@html.css("pre").last.text
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_status
|
93
|
+
@html.css("p")[1].text
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_url
|
97
|
+
number = @html.css("h2").first.text.delete("Paste \#")
|
98
|
+
URI("https://eval.in/#{number}")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-eval-in
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Woodruff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A Ruby interface to https://eval.in/.
|
42
|
+
email: william@tuffbizz.com
|
43
|
+
executables:
|
44
|
+
- eval-in
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".yardopts"
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- bin/eval-in
|
52
|
+
- lib/eval-in.rb
|
53
|
+
- lib/eval-in/exceptions.rb
|
54
|
+
- lib/eval-in/result.rb
|
55
|
+
homepage: https://github.com/woodruffw/ruby-eval-in
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.0.0
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.4.5.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: ruby-eval-in - A Ruby interface to https://eval.in/.
|
79
|
+
test_files: []
|
80
|
+
has_rdoc:
|