From 5ba7de702b2fbec1935245d993b4273ed872c557 Mon Sep 17 00:00:00 2001 From: Harman Singh Date: Sat, 15 Oct 2016 01:53:32 +0530 Subject: [PATCH 1/2] One list to rule them all --- config/config.rb | 19 +++---------------- config/languages.rb | 16 ++++++++++++++++ spec/euler_spec.rb | 17 +++++------------ 3 files changed, 24 insertions(+), 28 deletions(-) create mode 100644 config/languages.rb diff --git a/config/config.rb b/config/config.rb index 01d1db7..869264d 100644 --- a/config/config.rb +++ b/config/config.rb @@ -1,3 +1,5 @@ +require_relative 'languages' + # Initialize the Euler module's configuration to the default values. Euler.config do |config| @@ -57,22 +59,7 @@ end # Loads the default language definitions. -[ - - 'c', - 'coffeescript', - 'elixir', - 'haskell', - 'java', - 'javascript', - 'julia', - 'perl', - 'php', - 'python', - 'ruby', - 'scala' - -].each do |lang| +$supportedLanguagesList.each do |lang| require_relative "../languages/#{lang}" end diff --git a/config/languages.rb b/config/languages.rb new file mode 100644 index 0000000..8a21503 --- /dev/null +++ b/config/languages.rb @@ -0,0 +1,16 @@ +class Languages + $supportedLanguagesList = [ + 'c', + 'coffeescript', + 'elixir', + 'haskell', + 'java', + 'javascript', + 'julia', + 'perl', + 'php', + 'python', + 'ruby', + 'scala' + ] +end \ No newline at end of file diff --git a/spec/euler_spec.rb b/spec/euler_spec.rb index 0542d83..e779e70 100644 --- a/spec/euler_spec.rb +++ b/spec/euler_spec.rb @@ -1,5 +1,7 @@ require 'spec_helper' +require_relative '../config/languages' + describe Euler do before(:all) do @@ -25,18 +27,9 @@ end it "should have a few languages preregistered" do - Euler.get_language('c').should be_truthy - Euler.get_language('coffeescript').should be_truthy - Euler.get_language('elixir').should be_truthy - Euler.get_language('haskell').should be_truthy - Euler.get_language('java').should be_truthy - Euler.get_language('javascript').should be_truthy - Euler.get_language('julia').should be_truthy - Euler.get_language('perl').should be_truthy - Euler.get_language('php').should be_truthy - Euler.get_language('python').should be_truthy - Euler.get_language('ruby').should be_truthy - Euler.get_language('scala').should be_truthy + $supportedLanguagesList.each do |lang| + Euler.get_language(lang).should be_truthy + end end describe "Ruby language" do From 510c22f42cf9ef11e6e4fadc74cd678281545a67 Mon Sep 17 00:00:00 2001 From: Harman Singh Date: Thu, 20 Oct 2016 03:39:43 +0530 Subject: [PATCH 2/2] Added bash support --- config/config.rb | 2 +- languages/bash.rb | 25 +++++++++++++++++++++++++ spec/euler_spec.rb | 1 + templates/bash.sh | 3 +++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 languages/bash.rb create mode 100644 templates/bash.sh diff --git a/config/config.rb b/config/config.rb index 01d1db7..b6b5245 100644 --- a/config/config.rb +++ b/config/config.rb @@ -58,7 +58,7 @@ # Loads the default language definitions. [ - + 'bash', 'c', 'coffeescript', 'elixir', diff --git a/languages/bash.rb b/languages/bash.rb new file mode 100644 index 0000000..c8ec165 --- /dev/null +++ b/languages/bash.rb @@ -0,0 +1,25 @@ +Euler.register_language('bash', Class.new do + + # Run the bash solution + def run solution + `. #{file_path(solution)}` + end + + # Copy the template into the solution's directory + def init solution + FileUtils.cp(template_path, file_path(solution)) + end + + private + + # Returns the path to the solution + def file_path solution + "#{solution.dir}/#{solution.problem.id}.sh" + end + + # Returns the path to the ruby template + def template_path + "#{File.dirname(__FILE__)}/../templates/bash.sh" + end + +end) diff --git a/spec/euler_spec.rb b/spec/euler_spec.rb index 0542d83..3e3aa97 100644 --- a/spec/euler_spec.rb +++ b/spec/euler_spec.rb @@ -25,6 +25,7 @@ end it "should have a few languages preregistered" do + Euler.get_language('bash').should be_truthy Euler.get_language('c').should be_truthy Euler.get_language('coffeescript').should be_truthy Euler.get_language('elixir').should be_truthy diff --git a/templates/bash.sh b/templates/bash.sh new file mode 100644 index 0000000..689ddf6 --- /dev/null +++ b/templates/bash.sh @@ -0,0 +1,3 @@ +answer=0 + +echo $answer \ No newline at end of file