Class: Rorr::UI
- Inherits:
-
Object
- Object
- Rorr::UI
- Defined in:
- lib/rorr/ui.rb
Class Method Summary collapse
- .coderay(input) ⇒ Object
- .exit ⇒ Object
- .gets ⇒ Object
- .menu ⇒ Object
- .puts(msg) ⇒ Object
- .puts_with_delay(msg) ⇒ Object
- .question(question, index) ⇒ Object
- .repo_format(input, color = 'white') ⇒ Object
- .repo_rjust(input, length = 2) ⇒ Object
- .report ⇒ Object
- .skip ⇒ Object
- .sleep_with_setting ⇒ Object
- .solution(sol = nil) ⇒ Object
Class Method Details
.coderay(input) ⇒ Object
81 82 83 |
# File 'lib/rorr/ui.rb', line 81 def coderay(input) CodeRay.scan(input, :ruby).terminal end |
.exit ⇒ Object
77 78 79 |
# File 'lib/rorr/ui.rb', line 77 def exit "#{'exit'.red} to exit" end |
.gets ⇒ Object
8 9 10 |
# File 'lib/rorr/ui.rb', line 8 def gets Config.stdin ? Readline.readline('> ', true) : '' end |
.menu ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/rorr/ui.rb', line 21 def puts_with_delay "\nWelcom to RorR!".light_red sleep_with_setting puts "\nChoose the topic you want to start" puts "1. Don't ask me Ruby or Rails" puts "2. What's the return value?" puts "3. Make all test pass" puts "0. exit\n\n" end |
.puts(msg) ⇒ Object
4 5 6 |
# File 'lib/rorr/ui.rb', line 4 def puts(msg) Config.stdout.puts(msg) if Config.stdout end |
.puts_with_delay(msg) ⇒ Object
12 13 14 15 |
# File 'lib/rorr/ui.rb', line 12 def puts_with_delay(msg) sleep_with_setting puts(msg) end |
.question(question, index) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rorr/ui.rb', line 31 def question(question, index) sleep_with_setting puts "\n------------------------------" puts "Question #{index} :" puts "------------------------------\n\n" puts question.to_s puts "------------------------------\n" end |
.repo_format(input, color = 'white') ⇒ Object
65 66 67 |
# File 'lib/rorr/ui.rb', line 65 def repo_format(input, color = 'white') repo_rjust(input).public_send(color) end |
.repo_rjust(input, length = 2) ⇒ Object
69 70 71 |
# File 'lib/rorr/ui.rb', line 69 def repo_rjust(input, length = 2) input.to_s.rjust(length) end |
.report ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rorr/ui.rb', line 47 def report system 'clear' puts_with_delay "\n Test Report \n\n" sleep_with_setting puts ' Q. | Corr | Skip | Retry ' puts '-------------------------' Score.report.each do |r| puts " #{repo_rjust(r[:question], 3)} | #{repo_format(r[:correct], r[:color])} | #{repo_format(r[:skip], r[:color])} | #{repo_format(r[:retry])}" end puts '-------------------------' puts " #{repo_rjust(Score.total_count, 3)} | #{repo_format(Score.total[:correct])} | #{repo_format(Score.total[:skip])} | #{repo_format(Score.total[:retry])}" puts "\n#{repo_rjust('Correct Rate:', 14)} #{repo_rjust(Score.correct_rate, 7)}%".green puts "#{repo_rjust('Skip Rate:', 14)} #{repo_rjust(Score.skip_rate, 7)}%".light_blue puts "\n#{repo_rjust('Spend Time:', 14)} #{repo_rjust(Score.format_time, 7)}".light_magenta puts_with_delay "\nEnter to exit\n" gets end |
.skip ⇒ Object
73 74 75 |
# File 'lib/rorr/ui.rb', line 73 def skip "#{'skip'.light_blue} to next question" end |