rorr 0.1.0

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.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +155 -0
  8. data/Rakefile +9 -0
  9. data/bin/console +14 -0
  10. data/bin/rorr +5 -0
  11. data/bin/setup +8 -0
  12. data/lib/rorr.rb +22 -0
  13. data/lib/rorr/base.rb +15 -0
  14. data/lib/rorr/config.rb +14 -0
  15. data/lib/rorr/dont_ask_me.rb +60 -0
  16. data/lib/rorr/init.rb +24 -0
  17. data/lib/rorr/main.rb +28 -0
  18. data/lib/rorr/return_value.rb +68 -0
  19. data/lib/rorr/score.rb +76 -0
  20. data/lib/rorr/test_pass.rb +96 -0
  21. data/lib/rorr/ui.rb +86 -0
  22. data/lib/rorr/version.rb +3 -0
  23. data/lib/spec_helper.rb +4 -0
  24. data/rorr.gemspec +27 -0
  25. data/spec/check_answer/normal/001_spec.rb +14 -0
  26. data/spec/check_answer/normal/002_spec.rb +14 -0
  27. data/spec/check_answer/normal/003_spec.rb +14 -0
  28. data/spec/check_answer/normal/004_spec.rb +14 -0
  29. data/spec/check_answer/normal/005_spec.rb +11 -0
  30. data/spec/check_answer/normal/006_spec.rb +14 -0
  31. data/spec/check_answer/normal/007_spec.rb +14 -0
  32. data/spec/check_answer/normal/008_spec.rb +14 -0
  33. data/spec/check_answer/normal/009_spec.rb +11 -0
  34. data/spec/check_answer/normal/010_spec.rb +11 -0
  35. data/spec/rorr/config_spec.rb +15 -0
  36. data/spec/rorr/score_spec.rb +70 -0
  37. data/spec/rorr/ui_spec.rb +58 -0
  38. data/spec/spec_helper.rb +6 -0
  39. data/templates/README.erb +2 -0
  40. data/templates/Report.erb +14 -0
  41. data/templates/play.erb +3 -0
  42. data/topic/methods/normal/001.rb +15 -0
  43. data/topic/methods/normal/002.rb +17 -0
  44. data/topic/methods/normal/003.rb +19 -0
  45. data/topic/methods/normal/004.rb +16 -0
  46. data/topic/methods/normal/005.rb +16 -0
  47. data/topic/methods/normal/006.rb +15 -0
  48. data/topic/methods/normal/007.rb +16 -0
  49. data/topic/methods/normal/008.rb +17 -0
  50. data/topic/methods/normal/009.rb +16 -0
  51. data/topic/methods/normal/010.rb +17 -0
  52. data/topic/questions/normal/001.rb +19 -0
  53. data/topic/questions/normal/002.rb +19 -0
  54. data/topic/questions/normal/003.rb +1 -0
  55. data/topic/questions/normal/004.rb +1 -0
  56. data/topic/questions/normal/005.rb +4 -0
  57. data/topic/questions/normal/006.rb +14 -0
  58. data/topic/questions/normal/007.rb +14 -0
  59. data/topic/questions/normal/008.rb +14 -0
  60. data/topic/questions/normal/009.rb +14 -0
  61. data/topic/questions/normal/010.rb +14 -0
  62. data/topic/questions/normal/011.rb +4 -0
  63. data/topic/questions/normal/012.rb +4 -0
  64. data/topic/questions/normal/013.rb +5 -0
  65. data/topic/questions/normal/014.rb +5 -0
  66. data/topic/questions/normal/015.rb +5 -0
  67. data/topic/questions/normal/016.rb +5 -0
  68. data/topic/questions/normal/017.rb +2 -0
  69. data/topic/questions/normal/018.rb +2 -0
  70. data/topic/questions/normal/019.rb +1 -0
  71. data/topic/questions/normal/020.rb +14 -0
  72. data/topic/rails/001.rb +6 -0
  73. data/topic/rails/002.rb +12 -0
  74. data/topic/rails/003.rb +7 -0
  75. data/topic/rails/004.rb +20 -0
  76. data/topic/rails/005.rb +19 -0
  77. data/topic/rails/006.rb +17 -0
  78. data/topic/rails/007.rb +4 -0
  79. data/topic/rails/008.rb +6 -0
  80. data/topic/rails/009.rb +11 -0
  81. data/topic/rails/010.rb +9 -0
  82. data/topic/ruby/001.rb +5 -0
  83. data/topic/ruby/002.rb +9 -0
  84. data/topic/ruby/003.rb +8 -0
  85. data/topic/ruby/004.rb +4 -0
  86. data/topic/ruby/005.rb +5 -0
  87. data/topic/ruby/006.rb +8 -0
  88. data/topic/ruby/007.rb +8 -0
  89. data/topic/ruby/008.rb +7 -0
  90. data/topic/ruby/009.rb +5 -0
  91. data/topic/ruby/010.rb +6 -0
  92. metadata +207 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ca103a7ee93c621213da7adca4e7f21190dd9a0
4
+ data.tar.gz: b30bc7e8c6ffbb6e3106e67963a5da106fd051cc
5
+ SHA512:
6
+ metadata.gz: 6eefd4ae78e44825a3ded2572532f82e4075703af212b2f23a6b108ebb6a4e6d4887f51cc9f71cce4e78e70a629fd6c9bcda24ceefc1b27cd29a47c26e01937a
7
+ data.tar.gz: dbb6c97183b2041e578411765c260b5af6307605e9bb2fdcc0ec4ecd367164d806142cabd02b25a241b3cf62d541d86b9d06c46eccf8c79644e625a68f6239a7
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.11.2
6
+ script: bundle exec rspec --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rorr.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Leon Ji
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,155 @@
1
+ # RorR
2
+
3
+ [![Code Climate](https://codeclimate.com/github/mgleon08/rorr/badges/gpa.svg)](https://codeclimate.com/github/mgleon08/rorr)
4
+ [![Build Status](https://travis-ci.org/mgleon08/rorr.svg?branch=master)](https://travis-ci.org/mgleon08/rorr)
5
+
6
+ RorR(Ruby or Rails) is a test designed to evaluate the Ruby or Rails proficiency and artificial intelligence in a fun, interactive way.
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install rorr
12
+ ```
13
+
14
+ ##Getting Started
15
+
16
+ Then run the `rorr` command to start
17
+
18
+ ```
19
+ $ rorr
20
+ ```
21
+
22
+ Have three topics
23
+
24
+ ```ruby
25
+ Welcom to RorR!
26
+
27
+ Choose the topic you want to start
28
+ 1. Don't ask me Ruby or Rails
29
+ 2. What's the return value?
30
+ 3. Make all test pass
31
+ 0. exit
32
+
33
+ >
34
+ ```
35
+
36
+ ###Topic1: Don't ask me Ruby or Rails
37
+
38
+ This is to check whether you remember where Ruby ends and Rails.
39
+
40
+ ```ruby
41
+ Welcome to "Don't ask me Ruby or Rails"
42
+ Let's check whether you remember where Ruby ends and Rails
43
+
44
+ ------------------------------
45
+ Question 1 :
46
+ ------------------------------
47
+
48
+ Array(foo: :bar) # => [[:foo, :bar]]
49
+
50
+ ------------------------------
51
+ ruby or rails? (Type the ruby or rails to answer, skip to next question, exit to exit)
52
+
53
+ >
54
+ ```
55
+
56
+ ###Topic2: What's the return value?
57
+
58
+ This will show you the several pieces of code. You should type the code returned values to answer.
59
+
60
+ ```ruby
61
+ Welcome to "What's the return value?"
62
+ Let's check how much do you proficiency in ruby or rails
63
+
64
+ ------------------------------
65
+ Question 1 :
66
+ ------------------------------
67
+
68
+ 1 == 1.0
69
+
70
+ ------------------------------
71
+ What's the return value? (Type the Exception or SyntaxError if you expect it will return, skip to next question, exit to exit)
72
+
73
+ >
74
+ ```
75
+
76
+ You can type `Exception` & `SyntaxError` to answer if you expect it will return.
77
+
78
+
79
+ ###Topic3: Make all test pass
80
+
81
+ This will create a rorr directory in your current location where you find a `player.rb` and `README` file.
82
+
83
+ You can see `README` for instructions and write you answer to `player.rb`.
84
+
85
+ Type rorr to check if you've finished.
86
+
87
+ ```ruby
88
+ Welcome to "Make all tests pass"
89
+ Let's check how much do you proficiency in ruby or rails
90
+
91
+ Question 001 has been generated.
92
+ See the ./rorr/normal/001/README for instructions.
93
+
94
+ When you're done editing player.rb, type the rorr to check, skip to next question, exit to exit
95
+ >
96
+ ```
97
+
98
+
99
+ ###Test Report
100
+
101
+ In finish it will show you test report.
102
+
103
+ ```ruby
104
+ Test Report
105
+
106
+ Q. | Corr | Skip | Retry
107
+ -------------------------
108
+ 1. | ✓ | | 0
109
+ 2. | ✓ | | 0
110
+ 3. | ✓ | | 0
111
+ 4. | | ✓ | 0
112
+ 5. | | ✓ | 0
113
+ 6. | ✗ | | 0
114
+ 7. | ✗ | | 0
115
+ 8. | ✗ | | 0
116
+ 9. | ✓ | | 0
117
+ 10. | ✓ | | 0
118
+ -------------------------
119
+ 10 | 5 | 2 | 0
120
+
121
+ Correct Rate: 50.0%
122
+ Skip Rate: 20.0%
123
+
124
+ Spend Time: 00:00:33
125
+ ```
126
+
127
+ ##Run Options
128
+ You can run `rorr -h` for help
129
+
130
+ ```
131
+ Usage: rorr [options]
132
+ -t, --time SECONDS Delay each turn by seconds (default: 0.6)
133
+ -n, --number NUMBER Number of questions (default: 10, all = -1)
134
+ -s, --solution Show the solution (default: false)
135
+ -h, --help Show this message
136
+ ```
137
+
138
+ ##Questions Reference
139
+
140
+ If you have good questions welcome to pull requests or comments
141
+ on GitHub at `https://github.com/mgleon08/rorr`
142
+
143
+ * [Rails Hurts quiz](http://railshurts.com/quiz/)
144
+ * [11 Essential Ruby Interview Questions*](https://www.toptal.com/ruby/interview-questions)
145
+ * [15 Questions to Ask During a Ruby Interview](https://gist.github.com/ryansobol/5252653)
146
+ * [CoderByte](https://coderbyte.com/)
147
+
148
+ ## Contributing
149
+
150
+ Bug reports and pull requests are welcome on GitHub at `https://github.com/mgleon08/rorr`
151
+
152
+ ## Copyright & License
153
+
154
+ * Copyright (c) 2016 Leon Ji. See [LICENSE.txt](https://github.com/mgleon08/rorr/blob/master/LICENSE.txt) for further details.
155
+ * The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run RSpec"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.verbose = false
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rorr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/rorr"
3
+
4
+ init = Rorr::Init.new(ARGV)
5
+ init.run
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'optparse'
4
+ require 'colorize'
5
+ require 'readline'
6
+ require 'fileutils'
7
+ require 'erb'
8
+ require 'rspec'
9
+ require 'spec_helper'
10
+ require 'coderay'
11
+
12
+ require 'rorr/version'
13
+
14
+ require 'rorr/base'
15
+ require 'rorr/ui'
16
+ require 'rorr/init'
17
+ require 'rorr/main'
18
+ require 'rorr/score'
19
+ require 'rorr/config'
20
+ require 'rorr/dont_ask_me'
21
+ require 'rorr/return_value'
22
+ require 'rorr/test_pass'
@@ -0,0 +1,15 @@
1
+ module Rorr
2
+ module Base
3
+ def templates_path
4
+ File.expand_path('../../../templates', __FILE__)
5
+ end
6
+
7
+ def read_template(path)
8
+ ERB.new(File.read(path), nil, '-').result(binding)
9
+ end
10
+
11
+ def generate_file_base_path
12
+ Config.path_prefix + "/rorr/#{Config.level}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Rorr
2
+ class Config
3
+ @stdin = $stdin
4
+ @stdout = $stdout
5
+ @delay = 0.6
6
+ @level = 'normal'
7
+ @number = 9
8
+ @path_prefix = '.'
9
+ @solution = false
10
+ class << self
11
+ attr_accessor :stdin, :stdout, :delay, :topic, :level, :number, :path_prefix, :solution
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,60 @@
1
+ module Rorr
2
+ class DontAskMe
3
+ def initialize
4
+ @dir = %w(ruby rails)
5
+ @questions = []
6
+ create_questions
7
+ end
8
+
9
+ def start
10
+ system 'clear'
11
+ UI.puts "\nWelcome to #{"\"Don't ask me Ruby or Rails\"".light_cyan}"
12
+ UI.puts "Let's check whether you remember where Ruby ends and Rails\n"
13
+ Score.start
14
+ @questions.each.with_index(1) do |question, index|
15
+ UI.question(question[:qu], index)
16
+ Score.init(index)
17
+ UI.puts "ruby or rails? (Type the #{'ruby'.green} or #{'rails'.green} to answer, #{UI.skip}, #{UI.exit})\n\n"
18
+ while answer = UI.gets
19
+ case answer.downcase
20
+ when question[:ans]
21
+ UI.puts "Yes, this is #{question[:ans]}!".green
22
+ Score.add_correct
23
+ break
24
+ when 'ruby', 'rails'
25
+ UI.puts "No, this is not #{answer}!".red
26
+ Score.add_wrong
27
+ break
28
+ when 'skip'
29
+ UI.puts 'Skip the Question!'.light_blue
30
+ Score.add_skip
31
+ break
32
+ when 'exit' then exit
33
+ when '' then UI.puts_with_delay 'Please enter again!'.light_blue
34
+ else
35
+ UI.puts_with_delay 'Error, Please enter again!'.light_red
36
+ Score.add_retry
37
+ end
38
+ end
39
+ Score.add_report
40
+ UI.solution(question[:sol])
41
+ end
42
+ Score.finish
43
+ UI.report
44
+ end
45
+
46
+ private
47
+
48
+ def create_questions
49
+ @dir.each do |dir|
50
+ Dir[File.expand_path("../../../topic/#{dir}/*.rb", __FILE__)].each do |file|
51
+ content = File.open(file).read.split('# solution')
52
+ qu = UI.coderay(content[0])
53
+ sol = UI.coderay(content[1])
54
+ @questions << { qu: qu, ans: dir, sol: sol }
55
+ end
56
+ end
57
+ @questions = @questions.shuffle[0..Config.number]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module Rorr
2
+ class Init
3
+ def initialize(arguments)
4
+ @arguments = arguments
5
+ end
6
+
7
+ def run
8
+ parse_options
9
+ Rorr::Main.choose
10
+ end
11
+
12
+ private
13
+
14
+ def parse_options
15
+ options = OptionParser.new
16
+ options.banner = 'Usage: rorr [options]'
17
+ options.on('-t', '--time SECONDS', 'Delay each turn by seconds (default: 0.6)') { |seconds| Config.delay = seconds.to_f }
18
+ options.on('-n', '--number NUMBER', 'Number of questions (default: 10, all = 0)') { |number| Config.number = (number.to_i -1) }
19
+ options.on('-s', '--solution', 'Show the solution (default: false)') { |_number| Config.solution = true }
20
+ options.on('-h', '--help', 'Show this message') { puts(options); exit }
21
+ options.parse!(@arguments)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module Rorr
2
+ class Main
3
+ class << self
4
+ def choose
5
+ system 'clear'
6
+ UI.menu
7
+ while Config.topic = UI.gets
8
+ case Config.topic
9
+ when '1'
10
+ game = DontAskMe.new
11
+ break
12
+ when '2'
13
+ game = ReturnValue.new
14
+ break
15
+ when '3'
16
+ game = TestPass.new
17
+ break
18
+ when '0', 'exit' then exit
19
+ else
20
+ UI.puts_with_delay 'Please enter it again'.light_blue
21
+ end
22
+ end
23
+ UI.sleep_with_setting
24
+ game.start
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,68 @@
1
+ module Rorr
2
+ class ReturnValue
3
+ def initialize
4
+ @questions = []
5
+ create_questions
6
+ end
7
+
8
+ def start
9
+ system 'clear'
10
+ UI.puts "\nWelcome to #{"\"What's the return value?\"".light_cyan}"
11
+ UI.puts "Let's check how much do you proficiency in ruby or rails\n"
12
+ Score.start
13
+ @questions.each.with_index(1) do |question, index|
14
+ UI.question(question[:qu], index)
15
+ Score.init(index)
16
+ UI.puts "What's the return value? (Type the #{'Exception'.green} or #{'SyntaxError'.green} if you expect it will return, #{UI.skip}, #{UI.exit})\n\n"
17
+ while answer = UI.gets
18
+ case
19
+ when match_ans?(answer, question[:ans])
20
+ UI.puts 'Correct!'.green
21
+ Score.add_correct
22
+ break
23
+ when answer == 'skip'
24
+ UI.puts 'Skip the Question!'.light_blue
25
+ Score.add_skip
26
+ break
27
+ when answer == '' then UI.puts_with_delay 'Please enter again!'.light_blue
28
+ when answer == 'exit' then exit
29
+ else
30
+ UI.puts_with_delay 'Error, Please enter again!'.light_red
31
+ Score.add_retry
32
+ end
33
+ end
34
+ Score.add_report
35
+ UI.solution(question[:sol])
36
+ end
37
+ Score.finish
38
+ UI.report
39
+ end
40
+
41
+ private
42
+
43
+ def create_questions
44
+ UI.puts "\nCreate Questions...\n"
45
+ Dir[File.expand_path("../../../topic/questions/#{Config.level}/*.rb", __FILE__)].each do |file|
46
+ qu = UI.coderay(File.read(file))
47
+ ans = qu_ans(File.read(file))
48
+ sol = UI.coderay(ans)
49
+ @questions << { qu: "#{qu}\n", ans: ans, sol: "\n#{sol}\n" }
50
+ end
51
+ @questions = @questions.shuffle[0..Config.number]
52
+ end
53
+
54
+ def qu_ans(code)
55
+ eval(code)
56
+ rescue SyntaxError
57
+ SyntaxError
58
+ rescue
59
+ Exception
60
+ end
61
+
62
+ def match_ans?(stdin, answer)
63
+ eval(stdin) == answer
64
+ rescue
65
+ return false
66
+ end
67
+ end
68
+ end