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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +155 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/rorr +5 -0
- data/bin/setup +8 -0
- data/lib/rorr.rb +22 -0
- data/lib/rorr/base.rb +15 -0
- data/lib/rorr/config.rb +14 -0
- data/lib/rorr/dont_ask_me.rb +60 -0
- data/lib/rorr/init.rb +24 -0
- data/lib/rorr/main.rb +28 -0
- data/lib/rorr/return_value.rb +68 -0
- data/lib/rorr/score.rb +76 -0
- data/lib/rorr/test_pass.rb +96 -0
- data/lib/rorr/ui.rb +86 -0
- data/lib/rorr/version.rb +3 -0
- data/lib/spec_helper.rb +4 -0
- data/rorr.gemspec +27 -0
- data/spec/check_answer/normal/001_spec.rb +14 -0
- data/spec/check_answer/normal/002_spec.rb +14 -0
- data/spec/check_answer/normal/003_spec.rb +14 -0
- data/spec/check_answer/normal/004_spec.rb +14 -0
- data/spec/check_answer/normal/005_spec.rb +11 -0
- data/spec/check_answer/normal/006_spec.rb +14 -0
- data/spec/check_answer/normal/007_spec.rb +14 -0
- data/spec/check_answer/normal/008_spec.rb +14 -0
- data/spec/check_answer/normal/009_spec.rb +11 -0
- data/spec/check_answer/normal/010_spec.rb +11 -0
- data/spec/rorr/config_spec.rb +15 -0
- data/spec/rorr/score_spec.rb +70 -0
- data/spec/rorr/ui_spec.rb +58 -0
- data/spec/spec_helper.rb +6 -0
- data/templates/README.erb +2 -0
- data/templates/Report.erb +14 -0
- data/templates/play.erb +3 -0
- data/topic/methods/normal/001.rb +15 -0
- data/topic/methods/normal/002.rb +17 -0
- data/topic/methods/normal/003.rb +19 -0
- data/topic/methods/normal/004.rb +16 -0
- data/topic/methods/normal/005.rb +16 -0
- data/topic/methods/normal/006.rb +15 -0
- data/topic/methods/normal/007.rb +16 -0
- data/topic/methods/normal/008.rb +17 -0
- data/topic/methods/normal/009.rb +16 -0
- data/topic/methods/normal/010.rb +17 -0
- data/topic/questions/normal/001.rb +19 -0
- data/topic/questions/normal/002.rb +19 -0
- data/topic/questions/normal/003.rb +1 -0
- data/topic/questions/normal/004.rb +1 -0
- data/topic/questions/normal/005.rb +4 -0
- data/topic/questions/normal/006.rb +14 -0
- data/topic/questions/normal/007.rb +14 -0
- data/topic/questions/normal/008.rb +14 -0
- data/topic/questions/normal/009.rb +14 -0
- data/topic/questions/normal/010.rb +14 -0
- data/topic/questions/normal/011.rb +4 -0
- data/topic/questions/normal/012.rb +4 -0
- data/topic/questions/normal/013.rb +5 -0
- data/topic/questions/normal/014.rb +5 -0
- data/topic/questions/normal/015.rb +5 -0
- data/topic/questions/normal/016.rb +5 -0
- data/topic/questions/normal/017.rb +2 -0
- data/topic/questions/normal/018.rb +2 -0
- data/topic/questions/normal/019.rb +1 -0
- data/topic/questions/normal/020.rb +14 -0
- data/topic/rails/001.rb +6 -0
- data/topic/rails/002.rb +12 -0
- data/topic/rails/003.rb +7 -0
- data/topic/rails/004.rb +20 -0
- data/topic/rails/005.rb +19 -0
- data/topic/rails/006.rb +17 -0
- data/topic/rails/007.rb +4 -0
- data/topic/rails/008.rb +6 -0
- data/topic/rails/009.rb +11 -0
- data/topic/rails/010.rb +9 -0
- data/topic/ruby/001.rb +5 -0
- data/topic/ruby/002.rb +9 -0
- data/topic/ruby/003.rb +8 -0
- data/topic/ruby/004.rb +4 -0
- data/topic/ruby/005.rb +5 -0
- data/topic/ruby/006.rb +8 -0
- data/topic/ruby/007.rb +8 -0
- data/topic/ruby/008.rb +7 -0
- data/topic/ruby/009.rb +5 -0
- data/topic/ruby/010.rb +6 -0
- metadata +207 -0
data/lib/rorr/score.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Rorr
|
2
|
+
class Score
|
3
|
+
extend Base
|
4
|
+
@report = []
|
5
|
+
@total = { correct: 0, wrong: 0, skip: 0, retry: 0 }
|
6
|
+
class << self
|
7
|
+
attr_reader :single, :total, :report, :time, :start_time, :finish_time
|
8
|
+
|
9
|
+
def init(index)
|
10
|
+
@single = { question: "#{index}.", correct: '', skip: '', retry: 0, color: '' }
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_correct
|
14
|
+
total[:correct] += 1
|
15
|
+
single[:correct] = '✓'
|
16
|
+
single[:color] = 'green'
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_wrong
|
20
|
+
total[:wrong] += 1
|
21
|
+
single[:correct] = '✗'
|
22
|
+
single[:color] = 'red'
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_skip
|
26
|
+
total[:skip] += 1
|
27
|
+
single[:skip] = '✓'
|
28
|
+
single[:color] = 'light_blue'
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_retry
|
32
|
+
total[:retry] += 1
|
33
|
+
single[:retry] += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_report
|
37
|
+
report << single
|
38
|
+
end
|
39
|
+
|
40
|
+
def total_count
|
41
|
+
total[:correct] + total[:wrong] + total[:skip]
|
42
|
+
end
|
43
|
+
|
44
|
+
def correct_rate
|
45
|
+
((total[:correct].to_f / total_count.to_f) * 100).round(2)
|
46
|
+
end
|
47
|
+
|
48
|
+
def wrong_rate
|
49
|
+
((total[:wrong].to_f / total_count.to_f) * 100).round(2)
|
50
|
+
end
|
51
|
+
|
52
|
+
def skip_rate
|
53
|
+
((total[:skip].to_f / total_count.to_f) * 100).round(2)
|
54
|
+
end
|
55
|
+
|
56
|
+
def start
|
57
|
+
@start_time = Time.now
|
58
|
+
end
|
59
|
+
|
60
|
+
def finish
|
61
|
+
@finish_time = Time.now
|
62
|
+
@time = (finish_time - start_time).round(2)
|
63
|
+
end
|
64
|
+
|
65
|
+
def format_time
|
66
|
+
Time.at(Score.time).utc.strftime('%H:%M:%S')
|
67
|
+
end
|
68
|
+
|
69
|
+
def export_report
|
70
|
+
File.open(generate_file_base_path + '/Report', 'w') do |f|
|
71
|
+
f.write read_template(templates_path + '/report.erb')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Rorr
|
2
|
+
class TestPass
|
3
|
+
include Base
|
4
|
+
attr_accessor :index, :questions
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@questions = []
|
8
|
+
create_questions
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
system 'clear'
|
13
|
+
UI.puts "\nWelcome to #{'"Make all tests pass"'.light_cyan}"
|
14
|
+
UI.puts "Let's check how much do you proficiency in ruby or rails\n"
|
15
|
+
Score.start
|
16
|
+
@questions.each.with_index(1) do |question, index|
|
17
|
+
UI.sleep_with_setting
|
18
|
+
self.index = index - 1
|
19
|
+
Score.init(index)
|
20
|
+
generate_file(index)
|
21
|
+
while answer = UI.gets
|
22
|
+
case answer.downcase
|
23
|
+
when 'rorr'
|
24
|
+
if check_answer(index)
|
25
|
+
Score.add_correct
|
26
|
+
break
|
27
|
+
end
|
28
|
+
UI.sleep_with_setting
|
29
|
+
UI.puts "\nPlease Try Again. Make all tests pass."
|
30
|
+
UI.puts "Type #{'rorr'.green} to check, #{UI.skip}, #{UI.exit}"
|
31
|
+
Score.add_retry
|
32
|
+
when 'skip'
|
33
|
+
UI.puts 'Skip the Question!'.light_blue
|
34
|
+
Score.add_skip
|
35
|
+
break
|
36
|
+
when 'exit' then exit
|
37
|
+
else
|
38
|
+
UI.puts_with_delay 'Please enter again!'.light_blue
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Score.add_report
|
42
|
+
UI.solution(question[:sol])
|
43
|
+
end
|
44
|
+
Score.finish
|
45
|
+
Score.export_report
|
46
|
+
UI.report
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def create_questions
|
52
|
+
Dir[File.expand_path("../../../topic/methods/#{Config.level}/*.rb", __FILE__)].each do |file|
|
53
|
+
content = File.open(file).read.split("# methods\n")
|
54
|
+
method = content[1].split("\n")[0]
|
55
|
+
sol = UI.coderay(content[1])
|
56
|
+
@questions << { qu: content[0], me: method, sol: "\n#{sol}" }
|
57
|
+
end
|
58
|
+
@questions = @questions[0..Config.number]
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_file(index)
|
62
|
+
generate_question(index) unless File.exist?(generate_file_path(index))
|
63
|
+
UI.puts "\nQuestion #{basename(index).light_yellow} has been generated."
|
64
|
+
UI.puts "See the #{"#{generate_file_path(index)}/README".light_yellow} for instructions."
|
65
|
+
UI.puts "\nWhen you're done editing player.rb, type the #{'rorr'.green} to check, #{UI.skip}, #{UI.exit}\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_question(index)
|
69
|
+
FileUtils.mkdir_p(generate_file_path(index))
|
70
|
+
|
71
|
+
File.open(generate_file_path(index) + '/README', 'w') do |f|
|
72
|
+
f.write read_template(templates_path + '/README.erb')
|
73
|
+
end
|
74
|
+
|
75
|
+
File.open(generate_file_path(index) + '/play.rb', 'w') do |f|
|
76
|
+
f.write read_template(templates_path + '/play.erb')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate_file_path(index)
|
81
|
+
generate_file_base_path + "/#{basename(index)}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def check_answer(index)
|
85
|
+
spec = File.expand_path("../../../spec/check_answer/#{Config.level}/#{basename(index)}_spec.rb", __FILE__)
|
86
|
+
load "#{generate_file_path(index)}/play.rb"
|
87
|
+
check = RSpec::Core::Runner.run([spec])
|
88
|
+
RSpec.clear_examples
|
89
|
+
check == 0 ? true : false
|
90
|
+
end
|
91
|
+
|
92
|
+
def basename(index)
|
93
|
+
index.to_s.rjust(3, '0')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/rorr/ui.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Rorr
|
2
|
+
class UI
|
3
|
+
class << self
|
4
|
+
def puts(msg)
|
5
|
+
Config.stdout.puts(msg) if Config.stdout
|
6
|
+
end
|
7
|
+
|
8
|
+
def gets
|
9
|
+
Config.stdin ? Readline.readline('> ', true) : ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def puts_with_delay(msg)
|
13
|
+
sleep_with_setting
|
14
|
+
puts(msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
def sleep_with_setting
|
18
|
+
sleep(Config.delay)
|
19
|
+
end
|
20
|
+
|
21
|
+
def menu
|
22
|
+
puts_with_delay "\nWelcom to RorR!".light_red
|
23
|
+
sleep_with_setting
|
24
|
+
puts "\nChoose the topic you want to start"
|
25
|
+
puts "1. Don't ask me Ruby or Rails"
|
26
|
+
puts "2. What's the return value?"
|
27
|
+
puts "3. Make all test pass"
|
28
|
+
puts "0. exit\n\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
def question(question, index)
|
32
|
+
sleep_with_setting
|
33
|
+
puts "\n------------------------------"
|
34
|
+
puts "Question #{index} :"
|
35
|
+
puts "------------------------------\n\n"
|
36
|
+
puts question.to_s
|
37
|
+
puts "------------------------------\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def solution(sol = nil)
|
41
|
+
puts_with_delay "\nsolution:\n".light_magenta + sol.to_s if sol && Config.solution
|
42
|
+
puts_with_delay "\nEnter to next"
|
43
|
+
gets
|
44
|
+
system 'clear'
|
45
|
+
end
|
46
|
+
|
47
|
+
def report
|
48
|
+
system 'clear'
|
49
|
+
puts_with_delay "\n Test Report \n\n"
|
50
|
+
sleep_with_setting
|
51
|
+
puts ' Q. | Corr | Skip | Retry '
|
52
|
+
puts '-------------------------'
|
53
|
+
Score.report.each do |r|
|
54
|
+
puts " #{repo_rjust(r[:question], 3)} | #{repo_format(r[:correct], r[:color])} | #{repo_format(r[:skip], r[:color])} | #{repo_format(r[:retry])}"
|
55
|
+
end
|
56
|
+
puts '-------------------------'
|
57
|
+
puts " #{repo_rjust(Score.total_count, 3)} | #{repo_format(Score.total[:correct])} | #{repo_format(Score.total[:skip])} | #{repo_format(Score.total[:retry])}"
|
58
|
+
puts "\n#{repo_rjust('Correct Rate:', 14)} #{repo_rjust(Score.correct_rate, 7)}%".green
|
59
|
+
puts "#{repo_rjust('Skip Rate:', 14)} #{repo_rjust(Score.skip_rate, 7)}%".light_blue
|
60
|
+
puts "\n#{repo_rjust('Spend Time:', 14)} #{repo_rjust(Score.format_time, 7)}".light_magenta
|
61
|
+
puts_with_delay "\nEnter to exit\n"
|
62
|
+
gets
|
63
|
+
end
|
64
|
+
|
65
|
+
def repo_format(input, color = 'white')
|
66
|
+
repo_rjust(input).public_send(color)
|
67
|
+
end
|
68
|
+
|
69
|
+
def repo_rjust(input, length = 2)
|
70
|
+
input.to_s.rjust(length)
|
71
|
+
end
|
72
|
+
|
73
|
+
def skip
|
74
|
+
"#{'skip'.light_blue} to next question"
|
75
|
+
end
|
76
|
+
|
77
|
+
def exit
|
78
|
+
"#{'exit'.red} to exit"
|
79
|
+
end
|
80
|
+
|
81
|
+
def coderay(input)
|
82
|
+
CodeRay.scan(input, :ruby).terminal
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/rorr/version.rb
ADDED
data/lib/spec_helper.rb
ADDED
data/rorr.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rorr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rorr"
|
8
|
+
spec.version = Rorr::VERSION
|
9
|
+
spec.authors = ["Leon Ji"]
|
10
|
+
spec.email = ["mgleon08@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{The easiest way to evaluate the Ruby or Rails proficiency in a interactive way.}
|
13
|
+
spec.description = %q{This is a test designed to evaluate the Ruby or Rails proficiency and artificial intelligence in a fun, interactive way.}
|
14
|
+
spec.homepage = "https://github.com/mgleon08/rorr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.executables = ["rorr"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "colorize", "~> 0.8.1"
|
26
|
+
spec.add_development_dependency "coderay", "~> 1.1"
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#sort_keys' do
|
2
|
+
it do
|
3
|
+
hsh = { abc: 'hello', 'another_key' => 123, 4567 => 'third' }
|
4
|
+
expect(sort_keys(hsh)).to eq ["abc", "4567", "another_key"]
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
hsh = { 12345 => 'hello', 'rorr' => 123, foo: 'bar' }
|
8
|
+
expect(sort_keys(hsh)).to eq ["foo", "rorr", "12345"]
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
hsh = { a: 1, bbb: 2, cc: 3 }
|
12
|
+
expect(sort_keys(hsh)).to eq ["a", "cc", "bbb"]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#cal_chars' do
|
2
|
+
it do
|
3
|
+
str = "ababccabcacbc"
|
4
|
+
expect(cal_chars(str)).to eq ({ :a=>4, :b=>4, :c=>5 })
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
str = "oooxoxxoxoxoxoxoxoxo"
|
8
|
+
expect(cal_chars(str)).to eq ({ :o=>11, :x=>9 })
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
str = "rorrrorrorr"
|
12
|
+
expect(cal_chars(str)).to eq ({ :r=>8, :o=>3 })
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#alphabetize' do
|
2
|
+
it do
|
3
|
+
ary = ["Ruby", "Rails", "Python", "PHP", "Swift"]
|
4
|
+
expect(alphabetize(ary, false)).to eq ["PHP", "Python", "Rails", "Ruby", "Swift"]
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
ary = ["Ruby", "Rails", "Python", "PHP", "Swift"]
|
8
|
+
expect(alphabetize(ary, true)).to eq ["Swift", "Ruby", "Rails", "Python", "PHP"]
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
ary = ["Foo", "Bar", "Ruby", "Or", "Rails"]
|
12
|
+
expect(alphabetize(ary, true)).to eq ["Ruby", "Rails", "Or", "Foo", "Bar"]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#letter_capitalize' do
|
2
|
+
it do
|
3
|
+
str = "hello world"
|
4
|
+
expect(letter_capitalize(str)).to eq "Hello World"
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
str = "i love ruby or rails"
|
8
|
+
expect(letter_capitalize(str)).to eq "I Love Ruby Or Rails"
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
str = "this is rorr"
|
12
|
+
expect(letter_capitalize(str)).to eq "This Is Rorr"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#first_factorial' do
|
2
|
+
it do
|
3
|
+
str = "Hello"
|
4
|
+
expect(first_factorial(str)).to eq "olleH"
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
str = "I Love RorR"
|
8
|
+
expect(first_factorial(str)).to eq "RroR evoL I"
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
str = "Foo Bar"
|
12
|
+
expect(first_factorial(str)).to eq "raB ooF"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#letter_changes' do
|
2
|
+
it do
|
3
|
+
str = "hello*3"
|
4
|
+
expect(letter_changes(str)).to eq "ifmmp*3"
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
str = "have fun!"
|
8
|
+
expect(letter_changes(str)).to eq "ibwf gvo!"
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
str = "ruby or rails!"
|
12
|
+
expect(letter_changes(str)).to eq "svcz ps sbjmt!"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe '#longest_word' do
|
2
|
+
it do
|
3
|
+
str = "fun&!! time"
|
4
|
+
expect(longest_word(str)).to eq "time"
|
5
|
+
end
|
6
|
+
it do
|
7
|
+
str = "Hello# @@World"
|
8
|
+
expect(longest_word(str)).to eq "Hello"
|
9
|
+
end
|
10
|
+
it do
|
11
|
+
str = "ruby or rails"
|
12
|
+
expect(longest_word(str)).to eq "rails"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
describe '#fibonacci' do
|
2
|
+
it do
|
3
|
+
expect(fibonacci(8)).to eq [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
|
4
|
+
end
|
5
|
+
it do
|
6
|
+
expect(fibonacci(15)).to eq [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
|
7
|
+
end
|
8
|
+
it do
|
9
|
+
expect(fibonacci(20)).to eq [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]
|
10
|
+
end
|
11
|
+
end
|