euler-manager 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/config/config.rb +75 -0
- data/euler-manager.gemspec +1 -1
- data/euler-manager.sublime-project +4 -1
- data/{lib/euler/languages → languages}/coffeescript.rb +1 -1
- data/languages/java.rb +28 -0
- data/{lib/euler/languages → languages}/javascript.rb +1 -1
- data/{lib/euler/languages → languages}/python.rb +1 -1
- data/{lib/euler/languages → languages}/ruby.rb +1 -1
- data/{lib/euler/languages → languages}/scala.rb +2 -2
- data/lib/euler.rb +1 -64
- data/lib/euler/version.rb +1 -1
- data/spec/euler/solution_spec.rb +3 -3
- data/spec/euler_spec.rb +19 -0
- data/{lib/euler/languages/templates → templates}/coffeescript.coffee +0 -0
- data/templates/java.java +9 -0
- data/{lib/euler/languages/templates → templates}/javascript.js +0 -0
- data/{lib/euler/languages/templates → templates}/python.py +0 -0
- data/{lib/euler/languages/templates → templates}/ruby.rb +0 -0
- data/{lib/euler/languages/templates → templates}/scala.scala +0 -0
- metadata +19 -17
- data/lib/euler/languages.rb +0 -12
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 205ff380f78fc01c527cc428b8b36dfa8754dd96
         | 
| 4 | 
            +
              data.tar.gz: b81a0a9b99e5bbe9324a88da551ab9e9e3865f4d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a2609a2b03f20800f8a115464604d82c6700259d2618131fabc9e1a3af29b375ec4711f571d0dabec0ef65aeb3a2379be98c1adb71ad4932c786dd858d04b1c3
         | 
| 7 | 
            +
              data.tar.gz: c09705628babd1085d6d6d7914b1f86bbcf71d303b6d943f57784bb18f7b9b6514bfeb8f9a7c751f6d8683f6e9d48f21789630f924fb86b4c94029bc8d7d5f56
         | 
    
        data/README.md
    CHANGED
    
    
    
        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
         | 
    
        data/euler-manager.gemspec
    CHANGED
    
    | @@ -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'
         | 
    
        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)
         | 
| @@ -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 | 
| 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__)} | 
| 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 | 
            -
             | 
| 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
    
    
    
        data/spec/euler/solution_spec.rb
    CHANGED
    
    | @@ -50,7 +50,7 @@ describe Euler::Solution do | |
| 50 50 |  | 
| 51 51 | 
             
                dir = ds.call(solution)
         | 
| 52 52 |  | 
| 53 | 
            -
                File.directory?(dir).should  | 
| 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  | 
| 64 | 
            +
                solution.correct?.should be_truthy
         | 
| 65 65 |  | 
| 66 | 
            -
                solution.correct?.should  | 
| 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
         | 
| 
            File without changes
         | 
    
        data/templates/java.java
    ADDED
    
    
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
    
        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 | 
            +
              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- | 
| 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
         |