Class: RubyLearner::CLI
- Inherits:
-
Thor
- Object
- Thor
- RubyLearner::CLI
- Defined in:
- lib/ruby_learner/ruby_learner.rb
Overview
ruby_learner CLI main class
Instance Method Summary collapse
- #emacs_key(*args) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #install_emacs ⇒ Object
- #pair_popup(*args) ⇒ Object
- #restore(*args) ⇒ Object
- #sequential_check(*args) ⇒ Object
- #theme(*args) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby_learner/ruby_learner.rb', line 12 def initialize(*args) super @local_dir = "#{ENV['HOME']}/.ruby_learner" @workshop_dir = "#{@local_dir}/workshop" @restore_dir = "#{@local_dir}/restore" @datas_dir = "#{@local_dir}/.datas" @gem_dir = File.("../../../", __FILE__) Common.allocate.init_mk_files(gem_dir: @gem_dir, local_dir: @local_dir) end |
Instance Method Details
#emacs_key(*args) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ruby_learner/ruby_learner.rb', line 30 def emacs_key(*args) if [:image] system("open #{@datas_dir}/emacs_help.pdf") else system("cat #{@datas_dir}/emacs_help.org") end end |
#install_emacs ⇒ Object
129 130 131 132 |
# File 'lib/ruby_learner/ruby_learner.rb', line 129 def install_emacs file_path = "#{@datas_dir}/install_emacs.sh" system("sh #{file_path}") end |
#pair_popup(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_learner/ruby_learner.rb', line 40 def pair_popup(*args) if args[0].to_i == nil || args[0].to_i == 0 puts "your input is #{args[0]}. not exchange time." return end time = args[0].to_i popup_file = File.("../popup_per_time_for_background.rb", __FILE__) system("ruby #{popup_file} #{time} &") end |
#restore(*args) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ruby_learner/ruby_learner.rb', line 92 def restore(*args) restores = [] dir = Dir.open(@restore_dir) dir.each do |file| if file != '.' && file != '..' && file != '.empty.rb' restores << file.slice(1..file.length) end end sorted_restores = restores.sort_by{|item| item.to_i} sorted_restores.each{|item| item.insert(0, "[")} if [:refresh] system("rm -rf #{@restore_dir}") system("mkdir #{@restore_dir}") elsif args.empty? == true if sorted_restores.size < 20 puts sorted_restores else system("ls #{@restore_dir}") puts "\nlast 5 restore history." puts sorted_restores[-5..-1], "\n" end puts "If you want to open a restore_file, you execute 'ruby_learner restore [number]'" puts "ex) ruby_learner restore 3" print "If you want to remove all restore_files, you execute 'ruby_learner restore -r'" else case args[0].to_i when 0..sorted_restores.size-1 filename = sorted_restores[args[0].to_i] system("emacs #{@restore_dir}/#{filename}") else puts "you have #{sorted_restores.size} restore_files." puts "you must put 'ruby_learner restore 0~#{sorted_restores.size - 1}.'" end end end |
#sequential_check(*args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruby_learner/ruby_learner.rb', line 55 def sequential_check(*args) begin sequential_main = SequentialMain.new(@gem_dir, @local_dir) if args[0] == '-p' pair_timer = PairTimer.new do pair_timer.popup_per_time_for_exe(600) end args[0] = args[1] args[1] = args[2] end if [:drill] Thread.kill(pair_timer) if pair_timer != nil sequential_main.drill_contents elsif [:next] final_sec, final_par = sequential_main.get_final_history() next_sec, next_par = sequential_main.get_next_question(final_sec, final_par) sequential_main.action(next_sec, next_par) elsif [:last] sequential_main.last_re_action() else sequential_main.action(args[0], args[1]) end Thread.kill(pair_timer) if pair_timer != nil rescue => error puts "Error.message: #{error.}" puts 'sequential_check has 5-modes' puts 'mode-1: $ sequential_check [section:1~11] [part:1~], ex) sequential_check 1 3' puts 'mode-2: $ sequential_check -d, check drill contents' puts 'mode-3: $ sequential_check -n, learn next to your last-question' puts 'mode-4: $ sequential_check -l, learn your last-question' puts 'mode-5: $ sequential_check -p [1 2, -d, -n, -l], learn with partner, change per 10 minutes.' end end |
#theme(*args) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/ruby_learner/ruby_learner.rb', line 135 def theme(*args) args[0].chomp if args[0] == 'black' || args[0] == 'white' Common.allocate.change_theme(color: args[0], datas_dir: @datas_dir) else puts "you can change the theme_color, only black or white." end end |
#version ⇒ Object
24 25 26 |
# File 'lib/ruby_learner/ruby_learner.rb', line 24 def version puts RubyLearner::VERSION end |