Class: RubyLearner::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ruby_learner/ruby_learner.rb

Overview

ruby_learner CLI main class

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



14
15
16
17
18
19
20
21
22
# File 'lib/ruby_learner/ruby_learner.rb', line 14

def initialize(*args)
  super
  @local_dir = "#{ENV['HOME']}/.ruby_learner"
  @workshop_dir = "#{@local_dir}/workshop"
  @restore_dir = "#{@local_dir}/restore"
  @data_dir = "#{@local_dir}/.data"
  @gem_dir = File.expand_path("../../../", __FILE__)
  Common.allocate.init_mk_files(gem_dir: @gem_dir, local_dir: @local_dir)
end

Instance Method Details

#copspec(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruby_learner/ruby_learner.rb', line 55

def copspec(*args)
  begin
    if options[:sequential_check]
      CopSpec.copspec("#{@workshop_dir}/lib/workplace.rb")
    else
      CopSpec.copspec(args[0])
    end
  rescue => error
    puts "Error.message: #{error.message}"
  end
end

#emacs_key(*args) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ruby_learner/ruby_learner.rb', line 32

def emacs_key(*args)
  if options[:image]
    system("open #{@data_dir}/emacs_help.pdf")
  else
    system("cat #{@data_dir}/emacs_help.org")
  end
end

#install_emacsObject



127
128
129
130
# File 'lib/ruby_learner/ruby_learner.rb', line 127

def install_emacs
  file_path = "#{@data_dir}/install_emacs.sh"
  system("sh #{file_path}")
end

#pair_popup(*args) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ruby_learner/ruby_learner.rb', line 42

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
  file = File.expand_path("../pair_timer.rb", __FILE__)
  system("ruby #{file} #{time} &")
end

#restore(*args) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ruby_learner/ruby_learner.rb', line 114

def restore(*args)
  restore = Restore.new
  if options[:refresh]
    system("rm -rf #{@restore_dir}")
    system("mkdir #{@restore_dir}")
  elsif args.empty? == true
    restore.output
  else
    restore.open(args[0].to_i)
  end
end

#sequential_check(*args) ⇒ Object



75
76
77
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
106
107
108
# File 'lib/ruby_learner/ruby_learner.rb', line 75

def sequential_check(*args)
  begin
    mode = File.read("#{@data_dir}/sequential_mode.txt").chomp
    puts "active mode: #{mode}"
    sequential_check = nil
    if mode == 'nomal'
      sequential_check = SequentialCheck.new(@gem_dir, @local_dir)
    else
      sequential_check = SequentialCheckManual.new(@gem_dir, @local_dir)
    end
    if options[:drill]
      sequential_check.drill_contents
    elsif options[:next]
      sequential_check.next_action
    elsif options[:last]
      sequential_check.last_re_action
    elsif options[:manual]
      sequential_check.change_mode
      mode = File.read("#{@data_dir}/sequential_mode.txt").chomp
      puts "active mode changed: #{mode}"
    elsif options[:copspec]
      CopSpec.copspec("#{@workshop_dir}/lib/workplace.rb")
    elsif options[:workshop]
      puts "#{@data_dir}/chdir_workshop.sh"
      Dir.chdir "#{@workshop_dir}"
      exec 'fish'
    else
      sequential_check.action(args[0], args[1])
    end
  rescue => error
    puts "Error.message: #{error.message}"
    sequential_check.instruct_modes
  end
end

#theme(*args) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/ruby_learner/ruby_learner.rb', line 133

def theme(*args)
  args[0].chomp
  if args[0] == 'black' || args[0] == 'white'
    Common.allocate.change_theme(color: args[0], datas_dir: @data_dir)
  else
    puts "you can change the theme_color, only black or white."
  end
end

#versionObject



26
27
28
# File 'lib/ruby_learner/ruby_learner.rb', line 26

def version
  puts RubyLearner::VERSION
end