Class: SequentialMain

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

Instance Method Summary collapse

Constructor Details

#initialize(gem_dir, local_dir) ⇒ SequentialMain

Returns a new instance of SequentialMain.



6
7
8
9
10
11
12
# File 'lib/ruby_learner/sequential_main.rb', line 6

def initialize(gem_dir, local_dir)
  @gem_dir = gem_dir
  @local_dir = local_dir
  @workshop_dir = "#{local_dir}/workshop"
  @restore_dir = "#{local_dir}/restore"
  @datas_dir = "#{local_dir}/.datas"
end

Instance Method Details

#action(sec, par) ⇒ Object



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

def action(sec, par)
  puts "section_#{sec}/part_#{par}"
  seq_dir = "#{@gem_dir}/contents/questions/sequential_check/section_#{sec}/part_#{par}"
  typing_prac_class = TypingPractice.new(@local_dir, @gem_dir)
  typing_prac_class.prac_sequence(mode_dir: seq_dir)
  write_final_history(sec, par)
end

#drill_contentsObject



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

def drill_contents
  puts "section  \t part\t contents"
  puts "section_1\t 1~3\t standard_output"
  puts "section_2\t 1~3\t standard_input"
  puts "section_3\t 1~3\t standard_I/O summary"
  puts "section_4\t 1~3\t comparisons & conditionals"
  puts "section_5\t 1~3\t loop_methods"
  puts "section_6\t 1~3\t array & hash & symbol"
  puts "section_7\t 1~3\t function"
  puts "section_8\t 1~3\t class"
  puts "section_9\t 1~3\t regular_expression"
  puts "section_10\t 1~3\t file_operation"
  puts "section_11\t 1~3\t library"
end

#get_final_historyObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ruby_learner/sequential_main.rb', line 67

def get_final_history()
  final_history = ''
  final_sec = 0
  final_par = 0
  Dir::chdir(@datas_dir){
    File.open("final_history_sequential.txt") do |f|
    final_history = f.gets
    end
    final_sec = final_history.match(/(.*)\-/)[1].to_i
    final_par = final_history.match(/\-(.*)/)[1].to_i
  }
  return final_sec, final_par
end

#get_next_question(final_sec, final_par) ⇒ Object



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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/ruby_learner/sequential_main.rb', line 81

def get_next_question(final_sec, final_par)
  if final_sec == 1
    if final_par == 1
      next_sec = 1
      next_par = 2
    elsif final_par == 2
      next_sec = 1
      next_par = 3
    else
      next_sec = 2
      next_par = 1
    end
  elsif final_sec == 2
    if final_par == 1
      next_sec = 2
      next_par = 2
    elsif final_par == 2
      next_sec = 2
      next_par = 3
    else
      next_sec = 3
      next_par = 1
    end
  elsif final_sec == 3
    if final_par == 1
      next_sec = 3
      next_par = 2
    elsif final_par == 2
      next_sec = 3
      next_par = 3
    else
      next_sec = 4
      next_par = 1
    end
  elsif final_sec == 4
    if final_par == 1
      next_sec = 4
      next_par = 2
    elsif final_par == 2
      next_sec = 4
      next_par = 3
    else
      next_sec = 5
      next_par = 1
    end
  elsif final_sec == 5
    if final_par == 1
      next_sec = 5
      next_par = 2
    elsif final_par == 2
      next_sec = 5
      next_par = 3
    else
      next_sec = 6
      next_par = 1
    end
  elsif final_sec == 6
    if final_par == 1
      next_sec = 6
      next_par = 2
    elsif final_par == 2
      next_sec = 6
      next_par = 3
    else
      next_sec = 7
      next_par = 1
    end
  elsif final_sec == 7
    if final_par == 1
      next_sec = 7
      next_par = 2
    elsif final_par == 2
      next_sec = 7
      next_par = 3
    else
      next_sec = 8
      next_par = 1
    end
  elsif final_sec == 8
    if final_par == 1
      next_sec = 8
      next_par = 2
    elsif final_par == 2
      next_sec = 8
      next_par = 3
    else
      next_sec = 9
      next_par = 1
    end
  elsif final_sec == 9
    if final_par == 1
      next_sec = 9
      next_par = 2
    elsif final_par == 2
      next_sec = 9
      next_par = 3
    else
      next_sec = 10
      next_par = 1
    end
  elsif final_sec == 10
    if final_par == 1
      next_sec = 10
      next_par = 2
    elsif final_par == 2
      next_sec = 10
      next_par = 3
    else
      next_sec = 11
      next_par = 1
    end
  else
    if final_par == 1
      next_sec = 11
      next_par = 2
    elsif final_par == 2
      next_sec = 11
      next_par = 3
    else
      next_sec = 1
      next_par = 1
    end
  end
  return next_sec, next_par
end

#last_re_actionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_learner/sequential_main.rb', line 22

def last_re_action()
  final_sec, final_par = get_final_history()
  puts "section_#{final_sec}/part_#{final_par}"
  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}"
  system "cd #{@workshop_dir}/lib && emacs -nw -q -l #{emacs_dir}/init.el sentence.org workplace.rb"
  start_time = Time.now
  typing_prac_class = TypingPractice.new(@local_dir, @gem_dir)
  typing_prac_class.typing_discriminant
  elapsed_time = Common.allocate.time_check(start_time: start_time)
  p "#{elapsed_time} sec"
end

#write_final_history(sec, par) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_learner/sequential_main.rb', line 38

def write_final_history(sec, par)
  chmoded = 0
  file_dir = "#{@datas_dir}/final_history_sequential.txt"
  begin
    File.write(file_dir, "#{sec}-#{par}")
  rescue => error
    system "sudo chmod go+w #{file_dir}"
    chmoded += 1
    retry if chmoded < 2
    puts "FileWrite error #{error.message}"
    puts "you should input $sudo chmod go+w #{file_dir}"
  end
end