solve_pb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -3
- data/README.md +9 -3
- data/lib/solve_pb.rb +19 -14
- data/lib/solve_pb/{command_line.rb → args_inspector.rb} +3 -3
- data/lib/solve_pb/file_generator.rb +18 -36
- data/lib/solve_pb/problem.rb +4 -4
- data/lib/solve_pb/problem_parser.rb +0 -5
- data/lib/solve_pb/version.rb +1 -1
- data/template/{C++ → c++}/compile.sh +0 -0
- data/template/{C++ → c++}/main.cpp +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f1b4648ad4c326eb611a706ac42d1dc993a7ad6bf3086bad38999f677ce42a3
|
4
|
+
data.tar.gz: 437a91f41bf9ab20ff9ecb481f288eb44600b46e5f78b3e47c3ef8a715a6a0af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6c194f47177a826ef5bbcdda6e63d508a2e6e46354eb4ef2ed512edc772dceb9bc9a6134b78b25840fa16012f15c4b1ee4fbe5aa29d0c8ff17943796b3404b
|
7
|
+
data.tar.gz: 825629a352f22765b0c38756334dcb9884b0ecb8c4f541cd930051fe5758694e76a7008b2e2060d9153d225cea7de6f3280ad5dc2cee49ebb261379c230ec7b6
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
solve_pb (0.1.
|
4
|
+
solve_pb (0.1.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
byebug (10.0.2)
|
10
9
|
diff-lcs (1.3)
|
11
10
|
mini_portile2 (2.1.0)
|
12
11
|
nokogiri (1.6.8.1)
|
@@ -31,7 +30,6 @@ PLATFORMS
|
|
31
30
|
|
32
31
|
DEPENDENCIES
|
33
32
|
bundler (~> 1.16)
|
34
|
-
byebug
|
35
33
|
nokogiri (~> 1.6.7)
|
36
34
|
rake (~> 10.0)
|
37
35
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -22,10 +22,16 @@ Or install it yourself as:
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
bundle exec
|
25
|
+
bundle exec solve [hackerrank problem url] ["ruby", "c++"]
|
26
|
+
```
|
27
|
+
```ruby
|
28
|
+
bundle exec solve https://www.hackerrank.com/challenges/bomber-man ruby
|
29
|
+
```
|
30
|
+
```ruby
|
31
|
+
bundle exec solve https://www.hackerrank.com/challenges/bomber-man c++
|
26
32
|
```
|
27
33
|
|
28
|
-
We currently support Ruby (default)
|
34
|
+
We currently support Ruby (default).
|
29
35
|
|
30
36
|
## Development
|
31
37
|
|
@@ -35,7 +41,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
35
41
|
|
36
42
|
## Contributing
|
37
43
|
|
38
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nctruong/solve_pb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
39
45
|
|
40
46
|
## License
|
41
47
|
|
data/lib/solve_pb.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require 'fileutils'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'nokogiri'
|
7
|
+
|
2
8
|
require "solve_pb/version"
|
3
9
|
require "solve_pb/problem"
|
4
10
|
require "solve_pb/problem_parser"
|
5
|
-
require "solve_pb/
|
11
|
+
require "solve_pb/args_inspector"
|
6
12
|
require "solve_pb/file_generator"
|
7
13
|
|
8
14
|
module SolvePb
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
module ClassMethods
|
16
|
+
def root
|
17
|
+
File.dirname __dir__
|
18
|
+
end
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
def test
|
21
|
+
File.join root, "test"
|
22
|
+
end
|
16
23
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
SolvePb::FileGenerator.new.generate(args)
|
21
|
-
else
|
22
|
-
puts "Doing nothing. Abort!"
|
24
|
+
def main
|
25
|
+
args = SolvePb::ArgsInspector.new.parse
|
26
|
+
args.nil? ? 'Lack of URL' : SolvePb::FileGenerator.new.generate(args)
|
23
27
|
end
|
24
28
|
end
|
29
|
+
extend ClassMethods
|
25
30
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module SolvePb
|
2
|
-
class
|
2
|
+
class ArgsInspector
|
3
3
|
def parse
|
4
4
|
args = [:url, :lang]
|
5
5
|
@args = {}
|
@@ -11,8 +11,8 @@ module SolvePb
|
|
11
11
|
@args[:lang] = "ruby"
|
12
12
|
end
|
13
13
|
if @args[:url].nil?
|
14
|
-
puts "Please
|
15
|
-
puts "$
|
14
|
+
puts "Please input url. Example:"
|
15
|
+
puts "$ bundle exec solve https://www.hackerrank.com/challenges/bomber-man"
|
16
16
|
return nil
|
17
17
|
end
|
18
18
|
if @args.size > 2
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'solve_pb/problem_parser'
|
4
|
-
|
5
1
|
module SolvePb
|
6
2
|
class FileGenerator
|
7
3
|
attr_reader :problem, :language
|
@@ -11,69 +7,55 @@ module SolvePb
|
|
11
7
|
@language = args[:lang]
|
12
8
|
if problem
|
13
9
|
puts "Preparing workspace"
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
prepare_directory
|
11
|
+
prepare_readme
|
12
|
+
prepare_main_program
|
13
|
+
prepare_sample_input
|
14
|
+
prepare_sample_output
|
19
15
|
download_pb_statement
|
20
|
-
# create_runsh(problem, language)
|
21
|
-
else
|
22
|
-
puts "Couldn't fetch problem information. Please raise an issue on https://github.com/nctruong/solve_pb"
|
23
16
|
end
|
24
17
|
end
|
25
18
|
|
26
19
|
private
|
27
20
|
|
28
|
-
def
|
21
|
+
def prepare_directory
|
29
22
|
puts "\tcreate #{File.join(problem.name, '')}"
|
30
23
|
Dir.mkdir(problem.name)
|
31
24
|
end
|
32
25
|
|
33
|
-
def
|
26
|
+
def prepare_main_program
|
34
27
|
main_file_name = get_main_file_name
|
35
|
-
main_file_path = File.join(
|
36
|
-
SolvePb.root, "template",
|
37
|
-
language, main_file_name)
|
28
|
+
main_file_path = File.join(SolvePb.root, "template", language, main_file_name)
|
38
29
|
des_path = File.join(problem.name, main_file_name)
|
39
30
|
puts "\tcreate #{des_path}"
|
40
31
|
FileUtils.cp(main_file_path, des_path)
|
32
|
+
rescue
|
33
|
+
puts language
|
34
|
+
puts main_file_name
|
41
35
|
end
|
42
36
|
|
43
|
-
def
|
37
|
+
def prepare_sample_input
|
44
38
|
path = File.join(problem.name, "sample.input")
|
45
39
|
unless file_exists?(path)
|
46
|
-
open(path, 'w')
|
47
|
-
f.write(problem.sample_input)
|
48
|
-
end
|
40
|
+
open(path, 'w') { |f| f.write(problem.sample_input) }
|
49
41
|
puts "\tcreate #{path}"
|
50
42
|
end
|
51
43
|
end
|
52
44
|
|
53
|
-
def
|
45
|
+
def prepare_sample_output
|
54
46
|
path = File.join(problem.name, "sample.output")
|
55
47
|
unless file_exists?(path)
|
56
|
-
open(path, 'w')
|
57
|
-
f.write(problem.sample_output)
|
58
|
-
end
|
48
|
+
open(path, 'w') { |f| f.write(problem.sample_output) }
|
59
49
|
puts "\tcreate #{path}"
|
60
50
|
end
|
61
51
|
end
|
62
52
|
|
63
|
-
def create_runsh
|
64
|
-
runsh_path = File.join(
|
65
|
-
SolvePb.root, "template", language, "compile.sh")
|
66
|
-
des_path = File.join(problem.name, "run.sh")
|
67
|
-
puts "\tcreate #{des_path}"
|
68
|
-
FileUtils.cp(runsh_path, des_path)
|
69
|
-
FileUtils.chmod("a+x", des_path)
|
70
|
-
end
|
71
|
-
|
72
53
|
def get_main_file_name
|
73
54
|
return "main.rb" if language == "ruby"
|
55
|
+
return "main.cpp" if language == "c++"
|
74
56
|
end
|
75
57
|
|
76
|
-
def
|
58
|
+
def prepare_readme
|
77
59
|
path = File.join(problem.name, "readme.md")
|
78
60
|
unless file_exists?(path)
|
79
61
|
open(path, 'w') do |f|
|
@@ -93,7 +75,7 @@ module SolvePb
|
|
93
75
|
end
|
94
76
|
|
95
77
|
def file_exists?(path)
|
96
|
-
raise "\
|
78
|
+
raise "\tIgnore #{path}. It already exists." if File.exist?(path)
|
97
79
|
false
|
98
80
|
end
|
99
81
|
end
|
data/lib/solve_pb/problem.rb
CHANGED
@@ -4,10 +4,10 @@ module SolvePb
|
|
4
4
|
attr_accessor :url, :name, :sample_input, :sample_output
|
5
5
|
|
6
6
|
def initialize(url, name, sample_input, sample_output)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
@url = url
|
8
|
+
@name = name
|
9
|
+
@sample_input = sample_input
|
10
|
+
@sample_output = sample_output
|
11
11
|
end
|
12
12
|
|
13
13
|
def download_pdf
|
data/lib/solve_pb/version.rb
CHANGED
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solve_pb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Nguyen
|
@@ -73,14 +73,14 @@ files:
|
|
73
73
|
- bin/setup
|
74
74
|
- bin/solve
|
75
75
|
- lib/solve_pb.rb
|
76
|
-
- lib/solve_pb/
|
76
|
+
- lib/solve_pb/args_inspector.rb
|
77
77
|
- lib/solve_pb/file_generator.rb
|
78
78
|
- lib/solve_pb/problem.rb
|
79
79
|
- lib/solve_pb/problem_parser.rb
|
80
80
|
- lib/solve_pb/version.rb
|
81
81
|
- solve_pb.gemspec
|
82
|
-
- template/
|
83
|
-
- template/
|
82
|
+
- template/c++/compile.sh
|
83
|
+
- template/c++/main.cpp
|
84
84
|
- template/ruby/main.rb
|
85
85
|
homepage: https://github.com/nctruong/solve_pb
|
86
86
|
licenses:
|