Class: TypingPractice
- Inherits:
-
Object
- Object
- TypingPractice
- Defined in:
- lib/ruby_learner/typing_practice.rb
Instance Method Summary collapse
-
#initialize(local_dir, gem_dir) ⇒ TypingPractice
constructor
A new instance of TypingPractice.
- #loop_in_checks(check_mode, file) ⇒ Object
- #prac_sequence(mode_dir: String) ⇒ Object
- #rspec_check ⇒ Object
- #rubocop_check ⇒ Object
- #typing_discriminant ⇒ Object
Constructor Details
#initialize(local_dir, gem_dir) ⇒ TypingPractice
Returns a new instance of TypingPractice.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_learner/typing_practice.rb', line 8 def initialize(local_dir, gem_dir) @local_dir = local_dir @workshop_dir = "#{local_dir}/workshop" @restore_dir = "#{local_dir}/restore" @datas_dir = "#{local_dir}/.datas" @gem_dir = gem_dir theme_color = "" File.open("#{@datas_dir}/theme_color.txt") do |f| theme_color = f.gets.chomp end @emacs_dir = "#{@datas_dir}/.emacs.d/#{theme_color}" end |
Instance Method Details
#loop_in_checks(check_mode, file) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby_learner/typing_practice.rb', line 78 def loop_in_checks(check_mode, file) count = 0 flag_check = false flag_exit = false loop do count += 1 puts "---------------------------" puts "#{check_mode} try: #{count}" puts "---------------------------" flag_check = system "#{check_mode} #{file}" if flag_check == true puts "#{check_mode} check is clear!" break else Common.allocate.instruct_print select = STDIN.gets.chomp if select == 'exit' flag_exit = true break elsif select == 'answer' system "cd #{@workshop_dir}/lib && emacs -nw -q -l #{@emacs_dir}/answer.el sentence.org workplace.rb" else system "cd #{@workshop_dir}/lib && emacs -nw -q -l #{@emacs_dir}/init.el sentence.org workplace.rb" end end end return flag_check, flag_exit end |
#prac_sequence(mode_dir: String) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby_learner/typing_practice.rb', line 21 def prac_sequence(mode_dir: String) FileUtils.cp("#{mode_dir}/lib/workplace.rb", "#{@workshop_dir}/lib/workplace.rb") FileUtils.cp("#{mode_dir}/lib/sentence.org", "#{@workshop_dir}/lib/sentence.org") FileUtils.cp("#{mode_dir}/lib/answer.rb", "#{@workshop_dir}/lib/answer.rb") FileUtils.cp("#{mode_dir}/spec/workplace_spec.rb", "#{@workshop_dir}/spec/workplace_spec.rb") system "cd #{@workshop_dir}/lib && emacs -nw -q -l #{@emacs_dir}/init.el sentence.org workplace.rb" start_time = Time.now typing_discriminant elapsed_time = Common.allocate.time_check(start_time: start_time) p "#{elapsed_time} sec" end |
#rspec_check ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/ruby_learner/typing_practice.rb', line 62 def rspec_check puts "**********************************" puts "RSpec Error Check" puts "**********************************" file = "#{@workshop_dir}/spec/workplace_spec.rb" return loop_in_checks("rspec", file) end |
#rubocop_check ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/ruby_learner/typing_practice.rb', line 70 def rubocop_check puts "**********************************" puts "Rubocop Error Check" puts "**********************************" file = "#{@workshop_dir}/lib/workplace.rb" return loop_in_checks("rubocop", file) end |
#typing_discriminant ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_learner/typing_practice.rb', line 33 def typing_discriminant p 'typing_discriminant' loop do flag_rspec, flag_rs_exit = rspec_check if flag_rs_exit == true break end flag_rubocop, flag_rub_exit = rubocop_check if flag_rub_exit == true break end if flag_rspec == true && flag_rubocop == true puts "**********************************" puts "Final Error Check" puts "**********************************" stdout, stderr, status = Open3.capture3("rspec #{@workshop_dir}/spec/workplace_spec.rb") if status == 0 puts "your code is perfect." puts 'If you want to run your code, you execute the following command.' puts " $ ruby #{@workshop_dir}/lib/workplace.rb" break else puts "not perfect, please fix your code." end end end Common.allocate.save_restore(file: "#{@workshop_dir}/lib/workplace.rb", local_dir: @local_dir) end |