Class: Rorr::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/rorr/ui.rb

Class Method Summary collapse

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

.exitObject



77
78
79
# File 'lib/rorr/ui.rb', line 77

def exit
  "#{'exit'.red} to exit"
end

.getsObject



8
9
10
# File 'lib/rorr/ui.rb', line 8

def gets
  Config.stdin ? Readline.readline('> ', true) : ''
end


21
22
23
24
25
26
27
28
29
# File 'lib/rorr/ui.rb', line 21

def menu
  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

.reportObject



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

.skipObject



73
74
75
# File 'lib/rorr/ui.rb', line 73

def skip
  "#{'skip'.light_blue} to next question"
end

.sleep_with_settingObject



17
18
19
# File 'lib/rorr/ui.rb', line 17

def sleep_with_setting
  sleep(Config.delay)
end

.solution(sol = nil) ⇒ Object



40
41
42
43
44
45
# File 'lib/rorr/ui.rb', line 40

def solution(sol = nil)
  puts_with_delay "\nsolution:\n".light_magenta + sol.to_s if sol && Config.solution
  puts_with_delay "\nEnter to next"
  gets
  system 'clear'
end