Module: Ljudge
- Defined in:
- lib/ljudge.rb,
lib/ljudge/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.run(args, options, env = {}) ⇒ Object
env = { name1: ‘value1’, name2: ‘value2’ }.
- .to_option_str(hash) ⇒ Object
Class Method Details
.run(args, options, env = {}) ⇒ Object
env =
name1: 'value1',
name2: 'value2'
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ljudge.rb', line 26 def self.run(args, , env={}) command = "ljudge " command << to_option_str(args) << to_option_str() env.each { |key, value| command << "--env #{key} #{value} "} output = IO.popen(command, err: [:child, :out]).readlines.join begin JSON::restore(output) rescue JSON::ParserError output end end |
.to_option_str(hash) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ljudge.rb', line 38 def self.to_option_str(hash) str = "" hash.each do |key, value| if value.is_a? Array value.each { |args| str << '--' << key.to_s.gsub(/_/, '-') << ' ' << to_option_str(args) } else str << '--' << key.to_s.gsub(/_/, '-') << ' ' str << value.to_s << ' ' end end str end |