yooleroobee 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71e400e7f63e6a55f27f2d4ba736110f387a7ad8
4
+ data.tar.gz: f93cc90c3d2815d665b1d4700f7710a7b4f12702
5
+ SHA512:
6
+ metadata.gz: 3316775f58f7d0cb286f15dacae787a1ad88b843a880cd766b433abf7c55c2a7af26583873fc5205ec8cfa24a0e4ad61250ff6a655f7869901e7994dce3c9845
7
+ data.tar.gz: 6497d2e60f3d1e3ea1732f860e018d456ad2cc1f93945c0174becec8139f6cf10c59cebc9fe89b80e46de6ba3018e514a820f0d7842889f3c590b57356260403
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yooleroobee.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Yooleroobee
2
+
3
+ An an API for querying Project Euler AND a command line tool for creating test folders.
4
+
5
+ This is a fairly simple gem.
6
+
7
+ ## Installation
8
+
9
+ $ gem install yooleroobee
10
+
11
+ ## Usage
12
+
13
+ To create a folder in the present working directory just type:
14
+
15
+ $ yooleroobee new PROBLEM_NUMBER
16
+
17
+ for Problem 8, you will get:
18
+
19
+ - A New Directory called **8-largest-product-in-a-series**
20
+
21
+ And two files in that directory:
22
+
23
+ - **largest_product_in_a_series.rb**
24
+ - **largest_product_in_a_series_spec.rb**
25
+
26
+ The spec file will come with a pending RSpec test requiring the ruby file.
27
+
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/yooleroobee/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "yooleroobee"
3
+
4
+ Yooleroobee::CLI.start
@@ -0,0 +1,7 @@
1
+ require "yooleroobee/problems"
2
+ require "yooleroobee/cli"
3
+ require "yooleroobee/folder_creator"
4
+ require "yooleroobee/version"
5
+
6
+ module Yooleroobee
7
+ end
@@ -0,0 +1,20 @@
1
+ require 'thor'
2
+
3
+ module Yooleroobee
4
+ class CLI < Thor
5
+
6
+ desc 'new NUMBER', 'creates a new file structure for problem NUMBER'
7
+ def new(number)
8
+ problem = Yooleroobee::FolderCreator.new.for_problem(number)
9
+ say "Created the folder:"
10
+ say "./#{ problem.folder_name }", :green
11
+ say "And the files:"
12
+ say "#{ problem.ruby_file_name }", :green
13
+ say "#{ problem.test_name }", :green
14
+ say "for Problem #{ problem.number }: #{ problem.name }"
15
+ rescue
16
+ say "HEY: That folder already exists!", :bold
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ module Yooleroobee
5
+ class FolderCreator
6
+ attr_reader :dir
7
+ def initialize(opts = {})
8
+ @dir = opts.fetch(:dir) { Dir.new(Dir.pwd) }
9
+ end
10
+
11
+ def for_problem(number)
12
+ problem = Problems.new.problem(number)
13
+ Dir.mkdir(File.join(@dir.path, problem.folder_name))
14
+ dir = Dir.new(File.join(@dir.path, problem.folder_name))
15
+ File.open(File.join(dir.path, problem.test_name), "w") do |file|
16
+ file.puts problem.spec_body
17
+ end
18
+ File.open(File.join(dir.path, problem.ruby_file_name), "w") do |file|
19
+ file.puts problem.ruby_body
20
+ end
21
+ problem
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,102 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ module Yooleroobee
5
+ class Problems
6
+ def problem(number)
7
+ page = Nokogiri::HTML(open("https://projecteuler.net/problem=#{number}"))
8
+ name = page.css('h2')[0].text
9
+ number = page.css('#problem_info')[0].text.scan(/\d+/)[0].to_i
10
+ problem = Yooleroobee::ProblemParser.parse(page.css('.problem_content'))
11
+ Problem.new(name: name, number: number, problem: problem)
12
+ end
13
+ end
14
+ end
15
+
16
+ module Yooleroobee
17
+ class Problem
18
+ attr_reader :name, :number, :problem
19
+
20
+ def initialize(opts = {})
21
+ @name = opts.fetch(:name)
22
+ @number = opts.fetch(:number)
23
+ @problem = opts.fetch(:problem)
24
+ end
25
+
26
+ def folder_name
27
+ result = []
28
+ result << number
29
+ result << name.downcase.split
30
+ result.join("-")
31
+ end
32
+
33
+ def test_name
34
+ snake_name + "_spec.rb"
35
+ end
36
+
37
+ def ruby_file_name
38
+ snake_name + ".rb"
39
+ end
40
+
41
+ def snake_name
42
+ result = []
43
+ result << name.downcase.split
44
+ result.join("_")
45
+ end
46
+
47
+ def spec_body
48
+ header = []
49
+ header << "# PROBLEM #{number}: #{name}"
50
+ header << "# https://projecteuler.net/problem=#{number}"
51
+ header << "#"
52
+ header << problem.lines.map { |line| "# #{line}" }.join
53
+ header << "#"
54
+ header << "# WRITE YOUR TESTS!"
55
+ header << "\n"
56
+ header << "require_relative '#{snake_name}'"
57
+ header << "\n"
58
+ header << "describe #{class_name} do"
59
+ header << " it 'verifies the example' do"
60
+ header << " skip"
61
+ header << " end"
62
+ header << "end"
63
+ end
64
+
65
+ def ruby_body
66
+ body = []
67
+ body << "class #{class_name}"
68
+ body << ""
69
+ body << "end"
70
+ end
71
+
72
+ def class_name
73
+ returned_name = name.split.map(&:capitalize).join("").scan(/\w/).join("")
74
+ if returned_name[0] =~ /\d/
75
+ return "Euler" + returned_name
76
+ end
77
+ returned_name
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ module Yooleroobee
84
+ class ProblemParser
85
+ def self.parse(problem)
86
+ result = []
87
+ problem[0].traverse do |node|
88
+ case
89
+ when node.parent.name == "sup"
90
+ result
91
+ when node.name == "sup"
92
+ result << "^#{node.text}"
93
+ when node.text?
94
+ result << node.text
95
+ when node.name == "br"
96
+ result << "\n"
97
+ end
98
+ end
99
+ result.join.strip.gsub("\r","").gsub(/ *\n */,"\n")
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module Yooleroobee
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'tmpdir'
3
+
4
+ describe Yooleroobee::FolderCreator do
5
+ it 'creates a folder for a problem' do
6
+ Dir.mktmpdir do |dir|
7
+ test_dir = Dir.new(dir)
8
+ fc = Yooleroobee::FolderCreator.new(dir: test_dir)
9
+ fc.for_problem(9)
10
+ expect(test_dir.to_a).to include "9-special-pythagorean-triplet"
11
+ end
12
+ end
13
+
14
+ it 'creates a spec file for the problem' do
15
+ Dir.mktmpdir do |dir|
16
+ test_dir = Dir.new(dir)
17
+ test_file = File.open(File.join(__dir__,"/temp","/example_test.rb")).read
18
+ example_ruby_file = File.open(File.join(__dir__,"/temp","/special_pythagorean_triplet.rb")).read
19
+ fc = Yooleroobee::FolderCreator.new(dir: test_dir)
20
+ problem = fc.for_problem(9)
21
+ spec_file = File.read(File.join(dir, problem.folder_name, problem.test_name))
22
+ ruby_file = File.read(File.join(dir, problem.folder_name, problem.ruby_file_name))
23
+ expect(spec_file).to eq test_file
24
+ expect(ruby_file).to eq example_ruby_file
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yooleroobee::Problems do
4
+ let (:yooler) { Yooleroobee::Problems.new }
5
+
6
+ it 'knows the problem names' do
7
+ name = yooler.problem(9).name
8
+ expect(name).to eq "Special Pythagorean triplet"
9
+ end
10
+
11
+ it 'knows the problem numbers' do
12
+ number = yooler.problem(15).number
13
+ expect(number).to eq 15
14
+ end
15
+
16
+ it 'knows the problem content' do
17
+ problem = yooler.problem(9).problem
18
+ expect(problem).to eq ['A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,',
19
+ 'a^2 + b^2 = c^2',
20
+ 'For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.',
21
+ 'There exists exactly one Pythagorean triplet for which a + b + c = 1000.',
22
+ 'Find the product abc.'].join("\n")
23
+ end
24
+
25
+
26
+ describe '#class_name' do
27
+ it 'strips the class name of special symbols' do
28
+ class_name = yooler.problem(43).class_name
29
+ expect(class_name).to eq "SubstringDivisibility"
30
+ end
31
+
32
+ it 'knows the class name' do
33
+ class_name = yooler.problem(7).class_name
34
+ expect(class_name).to eq "Euler10001stPrime"
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'yooleroobee'
@@ -0,0 +1,18 @@
1
+ # PROBLEM 9: Special Pythagorean triplet
2
+ # https://projecteuler.net/problem=9
3
+ #
4
+ # A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
5
+ # a^2 + b^2 = c^2
6
+ # For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
7
+ # There exists exactly one Pythagorean triplet for which a + b + c = 1000.
8
+ # Find the product abc.
9
+ #
10
+ # WRITE YOUR TESTS!
11
+
12
+ require_relative 'special_pythagorean_triplet'
13
+
14
+ describe SpecialPythagoreanTriplet do
15
+ it 'verifies the example' do
16
+ skip
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class SpecialPythagoreanTriplet
2
+
3
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yooleroobee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yooleroobee"
8
+ spec.version = Yooleroobee::VERSION
9
+ spec.authors = "Kit Langton"
10
+ spec.email = "kit.langton@gmail.com"
11
+ spec.summary = "API and command line tool for Project Euler"
12
+ spec.description = "An API and command line tool for querying Project Euler and creating folders and tests for working on each problem."
13
+ spec.homepage = "https://github.com/sudokill/yooleroobee"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_runtime_dependency "nokogiri"
25
+ spec.add_runtime_dependency "thor"
26
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yooleroobee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kit Langton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: An API and command line tool for querying Project Euler and creating
84
+ folders and tests for working on each problem.
85
+ email: kit.langton@gmail.com
86
+ executables:
87
+ - yooleroobee
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/yooleroobee
97
+ - lib/yooleroobee.rb
98
+ - lib/yooleroobee/cli.rb
99
+ - lib/yooleroobee/folder_creator.rb
100
+ - lib/yooleroobee/problems.rb
101
+ - lib/yooleroobee/version.rb
102
+ - spec/folder_creator_spec.rb
103
+ - spec/problems_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/temp/example_test.rb
106
+ - spec/temp/special_pythagorean_triplet.rb
107
+ - spec/yooleroobee_spec.rb
108
+ - yooleroobee.gemspec
109
+ homepage: https://github.com/sudokill/yooleroobee
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.5
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: API and command line tool for Project Euler
133
+ test_files:
134
+ - spec/folder_creator_spec.rb
135
+ - spec/problems_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/temp/example_test.rb
138
+ - spec/temp/special_pythagorean_triplet.rb
139
+ - spec/yooleroobee_spec.rb