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,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rorr::Config do
4
+ subject(:config) { described_class }
5
+
6
+ it 'defalut value' do
7
+ expect(config.stdin).to eq(STDIN)
8
+ expect(config.stdout).to eq(STDOUT)
9
+ expect(config.delay).to eq(0.6)
10
+ expect(config.level).to eq('normal')
11
+ expect(config.number).to eq(9)
12
+ expect(config.path_prefix).to eq('.')
13
+ expect(config.solution).to eq(false)
14
+ end
15
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rorr::Score do
4
+ subject(:score) { described_class }
5
+
6
+ it 'default value' do
7
+ expect(score.report).to eq([])
8
+ expect(score.total).to eq({ correct: 0, wrong: 0, skip: 0, retry: 0 })
9
+ end
10
+
11
+ it '#init' do
12
+ score.init(1)
13
+ expect(score.single).to eq({ question: "1.", correct: '', skip: '', retry: 0, color:'' })
14
+ end
15
+
16
+ it '#add_correct' do
17
+ score.add_correct
18
+ expect(score.total[:correct]).to eq(1)
19
+ expect(score.single[:correct]).to eq('✓')
20
+ end
21
+
22
+ it '#add_wrong' do
23
+ score.add_wrong
24
+ expect(score.total[:correct]).to eq(1)
25
+ expect(score.single[:correct]).to eq('✗')
26
+ end
27
+
28
+ it '#add_skip' do
29
+ score.add_skip
30
+ expect(score.total[:skip]).to eq(1)
31
+ expect(score.single[:skip]).to eq('✓')
32
+ end
33
+
34
+ it '#add_retry' do
35
+ score.add_retry
36
+ expect(score.total[:retry]).to eq(1)
37
+ expect(score.single[:retry]).to eq(1)
38
+ end
39
+
40
+ it '#add_report' do
41
+ score.add_report
42
+ expect(score.report.length).to eq(1)
43
+ end
44
+
45
+ it '#total_count' do
46
+ expect(score.total_count).to eq(3)
47
+ end
48
+
49
+ it '#correct_rate' do
50
+ expect(score.correct_rate).to eq(((1.0/3.0)*100).round(2))
51
+ end
52
+
53
+ it '#wrong_rate' do
54
+ expect(score.correct_rate).to eq(((1.0/3.0)*100).round(2))
55
+ end
56
+
57
+ it '#skip_rate' do
58
+ expect(score.correct_rate).to eq(((1.0/3.0)*100).round(2))
59
+ end
60
+
61
+ it '#finish' do
62
+ score.start
63
+ time = score.finish
64
+ expect(time).to eq((score.finish_time - score.start_time).round(2))
65
+ end
66
+
67
+ it '#format_time' do
68
+ expect(score.format_time).to eq("00:00:00")
69
+ end
70
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rorr::UI do
4
+ subject(:ui) { described_class }
5
+
6
+ before(:each) do
7
+ @in = StringIO.new
8
+ @out = StringIO.new
9
+ @config = Rorr::Config
10
+ @config.stdin = @in
11
+ @config.stdout = @out
12
+ end
13
+
14
+ it "should add puts to out stream" do
15
+ ui.puts "foo"
16
+ expect(@out.string).to eq("foo\n")
17
+ end
18
+
19
+ it "should fetch gets from in stream" do
20
+ @in.puts "bar"
21
+ @in.rewind
22
+ allow(ui).to receive(:gets).and_return(@config.stdin.gets.chop!)
23
+ expect(ui.gets).to eq("bar")
24
+ end
25
+
26
+ it "should return empty string if no input" do
27
+ @config.stdin = nil
28
+ expect(ui.gets).to eq("")
29
+ end
30
+
31
+ it "should delay after puts when specified" do
32
+ @config.delay = 0.8
33
+ allow(ui).to receive(:sleep)
34
+ ui.puts_with_delay("foo")
35
+ expect(ui).to have_received(:sleep)
36
+ end
37
+
38
+ it "#sleep_with_setting" do
39
+ @config.delay = 1
40
+ allow(ui).to receive(:sleep_with_setting).and_return(true)
41
+ expect(ui.sleep_with_setting).to eq(true)
42
+ end
43
+
44
+ it "#repo_format" do
45
+ expect(ui.repo_format('hello')).to eq("\e[0;37;49mhello\e[0m")
46
+ expect(ui.repo_format('hello', 'green')).to eq("\e[0;32;49mhello\e[0m")
47
+ end
48
+
49
+ it "#repo_rjust" do
50
+ expect(ui.repo_rjust(1).class).to eq(String)
51
+ expect(ui.repo_rjust(2)).to eq(" 2")
52
+ expect(ui.repo_rjust(3, 5)).to eq(" 3")
53
+ end
54
+
55
+ it "#coderay" do
56
+ expect(ui.coderay('#hello')).to eq("\e[1;30m#hello\e[0m")
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rorr'
3
+
4
+ RSpec.configure do |config|
5
+ config.exclude_pattern = "#{File.expand_path('../check_answer/**/*', __FILE__)}"
6
+ end
@@ -0,0 +1,2 @@
1
+ <%= questions[index][:qu] %>
2
+ When you're done editing player.rb, type the rorr command to check.
@@ -0,0 +1,14 @@
1
+ Test Report
2
+
3
+ Q. | Corr | Skip | Retry
4
+ -------------------------
5
+ <%report.each do |r| -%>
6
+ <%="#{r[:question].rjust(3)} |#{r[:correct].rjust(4)} |#{r[:skip].rjust(4)} |#{r[:retry].to_s.rjust(4)}"%>
7
+ <%end-%>
8
+ -------------------------
9
+ <%="#{total_count.to_s.rjust(3)} |#{total[:correct].to_s.rjust(4)} |#{total[:skip].to_s.rjust(4)} |#{total[:retry].to_s.rjust(4)}"%>
10
+
11
+ Correct Rate: <%=correct_rate%>%
12
+ Skip Rate: <%=skip_rate%>%
13
+
14
+ Spend Time: <%=format_time%>
@@ -0,0 +1,3 @@
1
+ <%= questions[index][:me] %>
2
+ # add your code here
3
+ end
@@ -0,0 +1,15 @@
1
+ Write a function that sorts the keys in a hash by the length of the key as a string.
2
+
3
+ Example:
4
+
5
+ sort_keys({ abc: 'hello', 'another_key' => 123, 4567 => 'third' })
6
+ #=> ["abc", "4567", "another_key"]
7
+ sort_keys({ 12345 => 'hello', 'rorr' => 123, foo: 'bar' })
8
+ #=> ["foo", "rorr", "12345"]
9
+ sort_keys({ a: 1, bbb: 2, cc: 3 })
10
+ #=> ["a", "cc", "bbb"]
11
+
12
+ # methods
13
+ def sort_keys(hsh)
14
+ hsh.keys.map(&:to_s).sort_by(&:length)
15
+ end
@@ -0,0 +1,17 @@
1
+ Write a function that calculate the number of characters.
2
+
3
+ Example:
4
+
5
+ cal_chars("ababccabcacbc")
6
+ #=> {:a=>4, :b=>4, :c=>5}
7
+ cal_chars("oooxoxxoxoxoxoxoxoxo")
8
+ #=> {:o=>11, :x=>9}
9
+ cal_chars("rorrrorrorr")
10
+ #=> {:r=>8, :o=>3}
11
+
12
+ # methods
13
+ def cal_chars(str)
14
+ ans = Hash.new(0)
15
+ str.each_char { |char| ans[char.to_sym] += 1 }
16
+ ans
17
+ end
@@ -0,0 +1,19 @@
1
+ Write a function that sort with array.
2
+
3
+ Example:
4
+
5
+ alphabetize(["Ruby", "Rails", "Python", "PHP", "Swift"], false)
6
+ #=> ["PHP", "Python", "Rails", "Ruby", "Swift"]
7
+ alphabetize(["Ruby", "Rails", "Python", "PHP", "Swift"], true)
8
+ #=> ["Swift", "Ruby", "Rails", "Python", "PHP"]
9
+ alphabetize(["Foo", "Bar", "Ruby", "Or", "Rails"], true)
10
+ #=> ["Ruby", "Rails", "Or", "Foo", "Bar"]
11
+
12
+ # methods
13
+ def alphabetize(ary, bool)
14
+ if bool
15
+ ary.sort{ |item1, item2| item2 <=> item1}
16
+ else
17
+ ary.sort{ |item1, item2| item1 <=> item2}
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ Write a function to take the str parameter being passed and capitalize the first letter of each word.
2
+ Words will be separated by only one space.
3
+
4
+ Example:
5
+
6
+ letter_capitalize("hello world")
7
+ #=> "Hello World"
8
+ letter_capitalize("i love ruby or rails")
9
+ #=> "I Love Ruby Or Rails"
10
+ letter_capitalize("this is rorr")
11
+ #=> "This Is Rorr"
12
+
13
+ # methods
14
+ def letter_capitalize(str)
15
+ str = str.split(" ").each {|a| a.capitalize!}.join(" ")
16
+ end
@@ -0,0 +1,16 @@
1
+ Write a function to add up all the numbers from 1 to num.
2
+ For the test cases, the parameter num will be any number from 1 to 1000.
3
+
4
+ Example:
5
+
6
+ simple_adding(8)
7
+ #=> 36
8
+ simple_adding(12)
9
+ #=> 78
10
+ simple_adding(140)
11
+ #=> 8256
12
+
13
+ # methods
14
+ def simple_adding(num)
15
+ (1..num).reduce(0, :+)
16
+ end
@@ -0,0 +1,15 @@
1
+ Write a function to take the str parameter being passed and return the string in reversed order.
2
+
3
+ Example:
4
+
5
+ first_factorial("Hello")
6
+ #=> "olleH"
7
+ first_factorial("I Love RorR")
8
+ #=> "RroR evoL I"
9
+ first_factorial("Foo Bar")
10
+ #=> "raB ooF"
11
+
12
+ # methods
13
+ def first_factorial(str)
14
+ str.split("").reverse.join("")
15
+ end
@@ -0,0 +1,16 @@
1
+ Write a function to take the str parameter being passed and modify it using the following algorithm.
2
+ Replace every letter in the string with the letter following it in the alphabet (ie. c becomes d, z becomes a).
3
+
4
+ Example:
5
+
6
+ letter_changes("hello*3")
7
+ #=> "ifmmp*3"
8
+ letter_changes("have fun!")
9
+ #=> "ibwf gvo!"
10
+ letter_changes("ruby or rails!")
11
+ #=> "svcz ps sbjmt!"
12
+
13
+ # methods
14
+ def letter_changes(str)
15
+ str.tr!('a-z', 'b-za')
16
+ end
@@ -0,0 +1,17 @@
1
+ Write a function to take the sen parameter being passed and return the largest word in the string.
2
+ If there are two or more words that are the same length, return the first word from the string with that length.
3
+ Ignore punctuation and assume sen will not be empty.
4
+
5
+ Example:
6
+
7
+ longest_word("fun&!! time")
8
+ #=> "time"
9
+ longest_word("Hello# @@World")
10
+ #=> "Hello"
11
+ longest_word("ruby or rails")
12
+ #=> "rails"
13
+
14
+ # methods
15
+ def longest_word(str)
16
+ str.split(/[^\w]+/).max_by(&:length)
17
+ end
@@ -0,0 +1,16 @@
1
+ Write a function to take the num parameter being passed and return the factorial of it(e.g. if num = 4, return (4 * 3 * 2 * 1)).
2
+ For the test cases, the range will be between 1 and 18.
3
+
4
+ Example:
5
+
6
+ first_factorial(4)
7
+ #=> 24
8
+ first_factorial(8)
9
+ #=> 40320
10
+ first_factorial(18)
11
+ #=> 6402373705728000
12
+
13
+ # methods
14
+ def first_factorial(num)
15
+ (1..num).inject(1, :*)
16
+ end
@@ -0,0 +1,17 @@
1
+ Write a single line of Ruby code that prints the Fibonacci sequence of any length as an array.
2
+
3
+ (Hint: use inject)
4
+
5
+ Example:
6
+
7
+ fibonacci(8)
8
+ #=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
9
+ fibonacci(15)
10
+ #=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
11
+ fibonacci(20)
12
+ #=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946]
13
+
14
+ # methods
15
+ def fibonacci(int)
16
+ (1..int).inject( [0, 1] ) { | fib | fib << fib.last(2).inject(:+) }
17
+ end
@@ -0,0 +1,19 @@
1
+ VAL1 = 'Global'
2
+
3
+ module Test
4
+ VAL1 = 'Local'
5
+
6
+ class Foo
7
+ def method1
8
+ VAL1
9
+ end
10
+ end
11
+ end
12
+
13
+ class Test::Foo
14
+ def method2
15
+ VAL1
16
+ end
17
+ end
18
+
19
+ Test::Foo.new.method1
@@ -0,0 +1,19 @@
1
+ VAL2 = 'Global'
2
+
3
+ module Test
4
+ VAL2 = 'Local'
5
+
6
+ class Foo
7
+ def method1
8
+ VAL2
9
+ end
10
+ end
11
+ end
12
+
13
+ class Test::Foo
14
+ def method2
15
+ VAL2
16
+ end
17
+ end
18
+
19
+ Test::Foo.new.method2
@@ -0,0 +1 @@
1
+ 1 == 1.0
@@ -0,0 +1 @@
1
+ 1.eql?(1.0)
@@ -0,0 +1,4 @@
1
+ a = '1'
2
+ b = '1'
3
+
4
+ a.equal? b
@@ -0,0 +1,14 @@
1
+ module Test
2
+ def say
3
+ "Hi!"
4
+ end
5
+ end
6
+
7
+ class Foo
8
+ extend Test
9
+ def say
10
+ "Hello!"
11
+ end
12
+ end
13
+
14
+ Test.new.say
@@ -0,0 +1,14 @@
1
+ module Test
2
+ def say
3
+ "Hi!"
4
+ end
5
+ end
6
+
7
+ class Foo
8
+ extend Test
9
+ def say
10
+ "Hello!"
11
+ end
12
+ end
13
+
14
+ Foo.say
@@ -0,0 +1,14 @@
1
+ class Foo
2
+ def say
3
+ "Hi!"
4
+ end
5
+ end
6
+
7
+ class Bar < Foo
8
+ def say
9
+ "Hello! #{super}"
10
+ end
11
+ end
12
+
13
+ Bar.new.say
14
+