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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4100e834230766c8e4a27b5e852197d7bf77c8c298b7ad58f56274faf202d10f
4
- data.tar.gz: 8036ac1acf62c42f0cf34124854d199169200435a44208b49f5a2d9ff12afc48
3
+ metadata.gz: 4f1b4648ad4c326eb611a706ac42d1dc993a7ad6bf3086bad38999f677ce42a3
4
+ data.tar.gz: 437a91f41bf9ab20ff9ecb481f288eb44600b46e5f78b3e47c3ef8a715a6a0af
5
5
  SHA512:
6
- metadata.gz: 5c3fc86591fa7e413fbc93573015df4a093c9385e53f313f96d8daafc5c8f719dccbc479d01a00060f142e12a7c8e0871d550574c9cd65594dedd9b0bce80aec
7
- data.tar.gz: 1f0029e1c6f87eb58c9bad355b7214fd517b2da3aed0482a3cf6d177267e2e640aff8b3dc35bcb369fa752e9f9d0e476ab5db7cb453ae0d8b39c3060fb8ad0df
6
+ metadata.gz: 2f6c194f47177a826ef5bbcdda6e63d508a2e6e46354eb4ef2ed512edc772dceb9bc9a6134b78b25840fa16012f15c4b1ee4fbe5aa29d0c8ff17943796b3404b
7
+ data.tar.gz: 825629a352f22765b0c38756334dcb9884b0ecb8c4f541cd930051fe5758694e76a7008b2e2060d9153d225cea7de6f3280ad5dc2cee49ebb261379c230ec7b6
@@ -1,12 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solve_pb (0.1.0)
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 rake solve [hackerrank problem url]
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) and C++.
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/[USERNAME]/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.
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
 
@@ -1,25 +1,30 @@
1
- require "solve_pb/version"
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/command_line"
11
+ require "solve_pb/args_inspector"
6
12
  require "solve_pb/file_generator"
7
13
 
8
14
  module SolvePb
9
- def self.root
10
- File.dirname __dir__
11
- end
15
+ module ClassMethods
16
+ def root
17
+ File.dirname __dir__
18
+ end
12
19
 
13
- def self.test
14
- File.join root, "test"
15
- end
20
+ def test
21
+ File.join root, "test"
22
+ end
16
23
 
17
- def self.main
18
- args = SolvePb::Commandline.new.parse
19
- if args
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 Commandline
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 specify at least the problem's URL. Example:"
15
- puts "$ SolvePb https://www.hackerrank.com/challenges/acm-icpc-team"
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
- create_directory
15
- create_readme
16
- create_main_program
17
- create_sample_input
18
- create_sample_output
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 create_directory
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 create_main_program
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 create_sample_input
37
+ def prepare_sample_input
44
38
  path = File.join(problem.name, "sample.input")
45
39
  unless file_exists?(path)
46
- open(path, 'w') do |f|
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 create_sample_output
45
+ def prepare_sample_output
54
46
  path = File.join(problem.name, "sample.output")
55
47
  unless file_exists?(path)
56
- open(path, 'w') do |f|
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 create_readme
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 "\tignore #{path}. It already exists." if File.exist?(path)
78
+ raise "\tIgnore #{path}. It already exists." if File.exist?(path)
97
79
  false
98
80
  end
99
81
  end
@@ -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
- self.url = url
8
- self.name = name
9
- self.sample_input = sample_input
10
- self.sample_output = sample_output
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
@@ -1,8 +1,3 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'uri'
4
- require 'nokogiri'
5
-
6
1
  module SolvePb
7
2
  class ProblemParser
8
3
  def parse(url)
@@ -1,3 +1,3 @@
1
1
  module SolvePb
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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/command_line.rb
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/C++/compile.sh
83
- - template/C++/main.cpp
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: