class Rorr::UI

Public Class Methods

coderay(input) click to toggle source
# File lib/rorr/ui.rb, line 81
def coderay(input)
  CodeRay.scan(input, :ruby).terminal
end
exit() click to toggle source
# File lib/rorr/ui.rb, line 77
def exit
  "#{'exit'.red} to exit"
end
gets() click to toggle source
# File lib/rorr/ui.rb, line 8
def gets
  Config.stdin ? Readline.readline('> ', true) : ''
end
menu() click to toggle source
puts(msg) click to toggle source
# File lib/rorr/ui.rb, line 4
def puts(msg)
  Config.stdout.puts(msg) if Config.stdout
end
puts_with_delay(msg) click to toggle source
# File lib/rorr/ui.rb, line 12
def puts_with_delay(msg)
  sleep_with_setting
  puts(msg)
end
question(question, index) click to toggle source
# 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') click to toggle source
# 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) click to toggle source
# File lib/rorr/ui.rb, line 69
def repo_rjust(input, length = 2)
  input.to_s.rjust(length)
end
report() click to toggle source
# 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() click to toggle source
# File lib/rorr/ui.rb, line 73
def skip
  "#{'skip'.light_blue} to next question"
end
sleep_with_setting() click to toggle source
# File lib/rorr/ui.rb, line 17
def sleep_with_setting
  sleep(Config.delay)
end
solution(sol = nil) click to toggle source
# 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