euler-manager 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37a60549e5415b6cc0d09b8afea60b3e656e3db0
4
- data.tar.gz: 5e62eeec4e26819a192e9e9bbf3e96fdfaaea0c2
3
+ metadata.gz: 205ff380f78fc01c527cc428b8b36dfa8754dd96
4
+ data.tar.gz: b81a0a9b99e5bbe9324a88da551ab9e9e3865f4d
5
5
  SHA512:
6
- metadata.gz: b3d71ace9f4cd974a60762f71080ddfe2ada0a5db8ad3a64e0c18bf7f49d4e8289959a1774c382e5460715e9b7886daa6077af515f73d3b49c4553ab28f62e79
7
- data.tar.gz: c186c4e16eeb61f68b22198a4fa4802666cb775b34f4f281e0588d3d489feff86a3654e78b5963dc92ad6b3c0e0742ff75dc45b2ca9fc32115dc34cc9f7f485f
6
+ metadata.gz: a2609a2b03f20800f8a115464604d82c6700259d2618131fabc9e1a3af29b375ec4711f571d0dabec0ef65aeb3a2379be98c1adb71ad4932c786dd858d04b1c3
7
+ data.tar.gz: c09705628babd1085d6d6d7914b1f86bbcf71d303b6d943f57784bb18f7b9b6514bfeb8f9a7c751f6d8683f6e9d48f21789630f924fb86b4c94029bc8d7d5f56
data/README.md CHANGED
@@ -43,6 +43,7 @@ solution for problem number 1 then you can just run `$ euelr run` from `1/ruby`
43
43
 
44
44
  - coffeescript
45
45
  - javascript
46
+ - java
46
47
  - python
47
48
  - ruby
48
49
  - scala
data/config/config.rb ADDED
@@ -0,0 +1,75 @@
1
+ # Initialize the Euler module's configuration to the default values.
2
+ Euler.config do |config|
3
+
4
+ data_dir = "#{File.dirname(__FILE__)}/../data"
5
+
6
+ config.answers_file "#{data_dir}/answers.yml"
7
+ config.problems_dir "#{data_dir}/problems"
8
+
9
+ # The +directory_strategy+ is a Proc which returns the directory assigned to a
10
+ # a given solution.
11
+ config.directory_strategy lambda { |solution|
12
+ "#{Euler.root}/#{solution.problem_id}/#{solution.language}"
13
+ }
14
+
15
+ # The +create_directory_strategy+ is a Proc which is ran to create directories
16
+ # for solutions and anything else that is required to initialize a solution.
17
+ # By default a +README.md+ file is created at the root of the problem with the
18
+ # problem's name and description.
19
+ config.create_directory_strategy lambda { |solution|
20
+ problem = solution.problem
21
+ dir = solution.dir
22
+
23
+ FileUtils.mkdir_p(dir)
24
+ readme_path = "#{dir}/../README.md"
25
+ if not File.exists?(readme_path) then File.open(readme_path, 'w') do |f|
26
+ f.write("# [#{problem.name}](#{problem.url})\n\n#{problem.content}")
27
+ end end
28
+ }
29
+
30
+ # Attempts to parse a directory for the +problem_id+ and +language+. Returns
31
+ # a an array where the first element is the problem id and the second element
32
+ # is the language.
33
+ config.directory_parse_strategy lambda { |dir|
34
+ problem_id = (Regexp.new("#{Euler.root}/(\\d+)").match(dir) || [])[1]
35
+ language = (Regexp.new("#{Euler.root}/\\d+/(.+)").match(dir) || [])[1]
36
+
37
+ [problem_id, language]
38
+ }
39
+
40
+ # Returns every solution done so far.
41
+ config.all_solutions_strategy lambda {
42
+ Dir["#{Euler.root}/*"].select { |f|
43
+ File.directory?(f) and /\/\d+$/ === f
44
+ }.map { |problem_dir|
45
+ Dir["#{problem_dir}/*"].map { |solution_dir|
46
+ if File.directory?(solution_dir)
47
+ args = Euler.parse_params_from_directory(solution_dir)
48
+ Euler::Solution.new(*args)
49
+ else
50
+ nil
51
+ end
52
+ }
53
+ }.flatten.compact
54
+ }
55
+
56
+ end
57
+
58
+ # Loads the default language definitions.
59
+ [
60
+
61
+ 'coffeescript',
62
+ 'java',
63
+ 'javascript',
64
+ 'python',
65
+ 'ruby',
66
+ 'scala'
67
+
68
+ ].each do |lang|
69
+ require_relative "../languages/#{lang}"
70
+ end
71
+
72
+ # Attempt to load user defined configuration
73
+ begin
74
+ require Euler.euler_file_path
75
+ rescue; end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'bundler', '~> 1.5'
28
28
  spec.add_development_dependency 'rake'
29
29
 
30
- spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'rspec', '~> 2.0'
31
31
  spec.add_development_dependency 'fakefs', '~> 0.5.2'
32
32
 
33
33
  spec.add_development_dependency 'nokogiri'
@@ -5,7 +5,10 @@
5
5
  "follow_symlinks": true,
6
6
  "path": ".",
7
7
  "folder_exclude_patterns": [
8
- "*/scala/euler"
8
+ "*/scala/euler", "coverage", "pkg", "doc"
9
+ ],
10
+ "file_exclude_patterns": [
11
+ "*.gem"
9
12
  ]
10
13
  }
11
14
  ]
@@ -19,7 +19,7 @@ Euler.register_language('coffeescript', Class.new do
19
19
 
20
20
  # Returns the path to the template
21
21
  def template_path
22
- "#{File.dirname(__FILE__)}/templates/coffeescript.coffee"
22
+ "#{File.dirname(__FILE__)}/../templates/coffeescript.coffee"
23
23
  end
24
24
 
25
25
  end)
data/languages/java.rb ADDED
@@ -0,0 +1,28 @@
1
+ Euler.register_language('java', Class.new do
2
+
3
+ # Compile and run the java solution
4
+ def run solution
5
+ dir = File.dirname(file_path(solution))
6
+ Dir.chdir(dir)
7
+ `find #{Euler.root}/lib -type f -name "*.java" -not -name "java.java" -print | xargs javac`
8
+ `javac -cp .:#{Euler.root}/lib ./*.java && java Main`
9
+ end
10
+
11
+ # Copy the java template to the solution directory
12
+ def init solution
13
+ FileUtils.cp(template_path, file_path(solution))
14
+ end
15
+
16
+ private
17
+
18
+ # Returns the path of the solution
19
+ def file_path solution
20
+ "#{solution.dir}/Main.java"
21
+ end
22
+
23
+ # Returns the path of the java template
24
+ def template_path
25
+ "#{File.dirname(__FILE__)}/../templates/java.java"
26
+ end
27
+
28
+ end)
@@ -19,7 +19,7 @@ Euler.register_language('javascript', Class.new do
19
19
 
20
20
  # Returns the path to the template
21
21
  def template_path
22
- "#{File.dirname(__FILE__)}/templates/javascript.js"
22
+ "#{File.dirname(__FILE__)}/../templates/javascript.js"
23
23
  end
24
24
 
25
25
  end)
@@ -21,7 +21,7 @@ Euler.register_language('python', Class.new do
21
21
 
22
22
  # Returns the path to the template
23
23
  def template_path
24
- "#{File.dirname(__FILE__)}/templates/python.py"
24
+ "#{File.dirname(__FILE__)}/../templates/python.py"
25
25
  end
26
26
 
27
27
  end)
@@ -19,7 +19,7 @@ Euler.register_language('ruby', Class.new do
19
19
 
20
20
  # Returns the path to the ruby template
21
21
  def template_path
22
- "#{File.dirname(__FILE__)}/templates/ruby.rb"
22
+ "#{File.dirname(__FILE__)}/../templates/ruby.rb"
23
23
  end
24
24
 
25
25
  end)
@@ -4,7 +4,7 @@ Euler.register_language('scala', Class.new do
4
4
  def run solution
5
5
  dir = File.dirname(file_path(solution))
6
6
  Dir.chdir(dir)
7
- `scalac #{Euler.root}/lib/*.scala && scalac -cp .:#{Euler.root}/lib ./*.scala && scala Main`
7
+ `scalac #{Euler.root}/lib/*.scala && scalac -cp .:#{Euler.root}/lib ./*.scala && scala Main`
8
8
  end
9
9
 
10
10
  # Copy the scala template to the solution directory
@@ -21,7 +21,7 @@ Euler.register_language('scala', Class.new do
21
21
 
22
22
  # Returns the path of the scala template
23
23
  def template_path
24
- "#{File.dirname(__FILE__)}/templates/scala.scala"
24
+ "#{File.dirname(__FILE__)}/../templates/scala.scala"
25
25
  end
26
26
 
27
27
  end)
data/lib/euler.rb CHANGED
@@ -124,67 +124,4 @@ module Euler
124
124
 
125
125
  end
126
126
 
127
- # Initialize the Euler module's configuration to the default values.
128
- Euler.config do |config|
129
-
130
- data_dir = "#{File.dirname(__FILE__)}/../data"
131
-
132
- config.answers_file "#{data_dir}/answers.yml"
133
- config.problems_dir "#{data_dir}/problems"
134
-
135
- # The +directory_strategy+ is a Proc which returns the directory assigned to a
136
- # a given solution.
137
- config.directory_strategy lambda { |solution|
138
- "#{Euler.root}/#{solution.problem_id}/#{solution.language}"
139
- }
140
-
141
- # The +create_directory_strategy+ is a Proc which is ran to create directories
142
- # for solutions and anything else that is required to initialize a solution.
143
- # By default a +README.md+ file is created at the root of the problem with the
144
- # problem's name and description.
145
- config.create_directory_strategy lambda { |solution|
146
- problem = solution.problem
147
- dir = solution.dir
148
-
149
- FileUtils.mkdir_p(dir)
150
- readme_path = "#{dir}/../README.md"
151
- if not File.exists?(readme_path) then File.open(readme_path, 'w') do |f|
152
- f.write("# [#{problem.name}](#{problem.url})\n\n#{problem.content}")
153
- end end
154
- }
155
-
156
- # Attempts to parse a directory for the +problem_id+ and +language+. Returns
157
- # a an array where the first element is the problem id and the second element
158
- # is the language.
159
- config.directory_parse_strategy lambda { |dir|
160
- problem_id = (Regexp.new("#{Euler.root}/(\\d+)").match(dir) || [])[1]
161
- language = (Regexp.new("#{Euler.root}/\\d+/(.+)").match(dir) || [])[1]
162
-
163
- [problem_id, language]
164
- }
165
-
166
- # Returns every solution done so far.
167
- config.all_solutions_strategy lambda {
168
- Dir["#{Euler.root}/*"].select { |f|
169
- File.directory?(f) and /\/\d+$/ === f
170
- }.map { |problem_dir|
171
- Dir["#{problem_dir}/*"].map { |solution_dir|
172
- if File.directory?(solution_dir)
173
- args = Euler.parse_params_from_directory(solution_dir)
174
- Euler::Solution.new(*args)
175
- else
176
- nil
177
- end
178
- }
179
- }.flatten.compact
180
- }
181
-
182
- end
183
-
184
- # Include the default language definitions.
185
- require_relative 'euler/languages'
186
-
187
- # Attempt to load user defined configuration
188
- begin
189
- require Euler.euler_file_path
190
- rescue; end
127
+ require_relative './../config/config'
data/lib/euler/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Euler
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -50,7 +50,7 @@ describe Euler::Solution do
50
50
 
51
51
  dir = ds.call(solution)
52
52
 
53
- File.directory?(dir).should be_true
53
+ File.directory?(dir).should be_truthy
54
54
  end
55
55
 
56
56
  it "correct? method should return true of the solution is correct and false otherwise" do
@@ -61,9 +61,9 @@ describe Euler::Solution do
61
61
  problem = solution.problem
62
62
  allow(problem).to receive(:answer).and_return('42', '9001')
63
63
 
64
- solution.correct?.should be_true
64
+ solution.correct?.should be_truthy
65
65
 
66
- solution.correct?.should be_false
66
+ solution.correct?.should be_falsey
67
67
  end
68
68
 
69
69
  end
data/spec/euler_spec.rb CHANGED
@@ -24,4 +24,23 @@ describe Euler do
24
24
  Euler.directory_strategy *args
25
25
  end
26
26
 
27
+ it "should have a few languages preregistered" do
28
+ Euler.get_language('coffeescript').should be_truthy
29
+ Euler.get_language('java').should be_truthy
30
+ Euler.get_language('javascript').should be_truthy
31
+ Euler.get_language('python').should be_truthy
32
+ Euler.get_language('coffeescript').should be_truthy
33
+ Euler.get_language('scala').should be_truthy
34
+ end
35
+
36
+ describe "Ruby language" do
37
+
38
+ it "'s template should be a file" do
39
+ ruby = Euler.get_language('ruby')
40
+ tmpl = ruby.send(:template_path)
41
+ File.exists?(tmpl).should be_truthy
42
+ end
43
+
44
+ end
45
+
27
46
  end
@@ -0,0 +1,9 @@
1
+ public class Main {
2
+
3
+ public static void main(String[] args) {
4
+ int answer = 0;
5
+
6
+ System.out.println(answer);
7
+ }
8
+
9
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euler-manager
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 Yaworsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: fakefs
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +137,7 @@ files:
137
137
  - README.md
138
138
  - Rakefile
139
139
  - bin/euler
140
+ - config/config.rb
140
141
  - data/answers.yml
141
142
  - data/problems/1.yml
142
143
  - data/problems/10.yml
@@ -607,19 +608,14 @@ files:
607
608
  - example/lib/euler.py
608
609
  - example/lib/euler.rb
609
610
  - example/lib/euler.scala
611
+ - languages/coffeescript.rb
612
+ - languages/java.rb
613
+ - languages/javascript.rb
614
+ - languages/python.rb
615
+ - languages/ruby.rb
616
+ - languages/scala.rb
610
617
  - lib/euler.rb
611
618
  - lib/euler/errors.rb
612
- - lib/euler/languages.rb
613
- - lib/euler/languages/coffeescript.rb
614
- - lib/euler/languages/javascript.rb
615
- - lib/euler/languages/python.rb
616
- - lib/euler/languages/ruby.rb
617
- - lib/euler/languages/scala.rb
618
- - lib/euler/languages/templates/coffeescript.coffee
619
- - lib/euler/languages/templates/javascript.js
620
- - lib/euler/languages/templates/python.py
621
- - lib/euler/languages/templates/ruby.rb
622
- - lib/euler/languages/templates/scala.scala
623
619
  - lib/euler/problem.rb
624
620
  - lib/euler/solution.rb
625
621
  - lib/euler/version.rb
@@ -628,6 +624,12 @@ files:
628
624
  - spec/euler/solution_spec.rb
629
625
  - spec/euler_spec.rb
630
626
  - spec/spec_helper.rb
627
+ - templates/coffeescript.coffee
628
+ - templates/java.java
629
+ - templates/javascript.js
630
+ - templates/python.py
631
+ - templates/ruby.rb
632
+ - templates/scala.scala
631
633
  homepage: https://github.com/yaworsw/euler-manager
632
634
  licenses:
633
635
  - MIT
@@ -1,12 +0,0 @@
1
- # Loads the default language definitions using a white list.
2
- [
3
-
4
- 'coffeescript',
5
- 'javascript',
6
- 'python',
7
- 'ruby',
8
- 'scala'
9
-
10
- ].each do |lang|
11
- require_relative "./languages/#{lang}"
12
- end