Class: SequentialMain

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

Instance Method Summary collapse

Constructor Details

#initialize(gem_dir, workshop_dir) ⇒ SequentialMain

Returns a new instance of SequentialMain.



5
6
7
8
# File 'lib/ruby_learner/sequential_main.rb', line 5

def initialize(gem_dir, workshop_dir)
  @gem_dir = gem_dir
  @workshop_dir = workshop_dir
end

Instance Method Details

#action(sec, par) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ruby_learner/sequential_main.rb', line 10

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

#drill_contentsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby_learner/sequential_main.rb', line 32

def drill_contents
  puts "section_1  1~3"
  puts "section_2  1~3"
  puts "section_3  1~2"
  puts "section_4  1"
  puts "section_5  1~2"
  puts "section_6  1~4"
  puts "section_7  1~2"
  puts "section_8  1"
  puts "section_9  1~3"
  puts "section_10 1~2"
  puts "section_11 1~2"
end

#get_final_history(gem_dir) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_learner/sequential_main.rb', line 46

def get_final_history(gem_dir)
  docs_dir = "#{gem_dir}/lib/datas"
  final_history = ''
  final_sec = 0
  final_par = 0
  Dir::chdir(docs_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



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
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
# File 'lib/ruby_learner/sequential_main.rb', line 61

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
    else
      next_sec = 4
      next_par = 1
    end
  elsif final_sec == 4
    next_sec = 5
    next_par = 1
  elsif final_sec == 5
    if final_par == 1
      next_sec = 5
      next_par = 2
    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
    elsif final_par == 3
      next_sec = 6
      next_par = 4
    else
      next_sec = 7
      next_par = 1
    end
  elsif final_sec == 7
    if final_par == 1
      next_sec = 7
      next_par = 2
    else
      next_sec = 8
      next_par = 1
    end
  elsif final_sec == 8
    next_sec = 9
    next_par = 1
  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
    else
      next_sec = 11
      next_par = 1
    end
  else
    if final_par == 1
      next_sec = 11
      next_par = 2
    else
      next_sec = 1
      next_par = 1
    end
  end
  return next_sec, next_par
end

#write_final_history(sec, par) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_learner/sequential_main.rb', line 18

def write_final_history(sec, par)
  chmoded = 0
  file_dir = "#{@gem_dir}/lib/datas/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