Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ solution for problem number 1 then you can just run `$ euelr run` from `1/ruby`

## Supported Programming Languages

- Bash
- C
- coffeescript
- elixir
Expand Down
19 changes: 3 additions & 16 deletions config/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'languages'

# Initialize the Euler module's configuration to the default values.
Euler.config do |config|

Expand Down Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions config/languages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Languages
$supportedLanguagesList = [
'bash',
'c',
'coffeescript',
'elixir',
'haskell',
'java',
'javascript',
'julia',
'perl',
'php',
'python',
'ruby',
'scala'
]
end
25 changes: 25 additions & 0 deletions languages/bash.rb
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 5 additions & 12 deletions spec/euler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'spec_helper'

require_relative '../config/languages'

describe Euler do

before(:all) do
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions templates/bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
answer=0

echo $answer