Class: Training
- Inherits:
-
Object
- Object
- Training
- Defined in:
- lib/shunkuntype/training.rb
Instance Method Summary collapse
-
#counter(word1, word2) ⇒ Object
count correct spelling.
- #init_proc(file_name) ⇒ Object
-
#initialize(val_i) ⇒ Training
constructor
A new instance of Training.
- #keep_record(start_time, file_name, period) ⇒ Object
-
#loop_thread(sec) ⇒ Object
time loop.
-
#print_keyboard ⇒ Object
print key positions.
- #size_training(file_name, data, start_time) ⇒ Object
- #time_training(base_name, data, start_time) ⇒ Object
- #type_loop(data) ⇒ Object
Constructor Details
#initialize(val_i) ⇒ Training
Returns a new instance of Training.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/shunkuntype/training.rb', line 2 def initialize(val_i) val_i ||= 47 data_dir=File.('../../../lib/data', __FILE__) base_name="STEP-#{val_i}.txt" file_name=File.join(data_dir,base_name) @period = 60 @counter = 0 @time_flag=true print_keyboard start_time,data=init_proc(file_name) #size_training(file_name,data,start_time) time_training(base_name,data,start_time) end |
Instance Method Details
#counter(word1, word2) ⇒ Object
count correct spelling
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/shunkuntype/training.rb', line 19 def counter(word1,word2) ws1=word1.split(/\s+/) ws2=word2.split(/\s+/) i,j=0,0 while (i < ws1.length) && (j < ws2.length) do if ws1[i] == ws2[j] then @counter+=1 end i+=1 j+=1 end puts @counter end |
#init_proc(file_name) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/shunkuntype/training.rb', line 52 def init_proc(file_name) data=File.readlines(file_name) data.each{|word| print word } print "\nRepeat above sentences. Type return-key to start." p '' line=STDIN.gets start_time = Time.now return start_time,data end |
#keep_record(start_time, file_name, period) ⇒ Object
62 63 64 65 66 |
# File 'lib/shunkuntype/training.rb', line 62 def keep_record(start_time,file_name,period) data_file=open(Shunkuntype::TRAIN_FILE,"a") data_file << "#{start_time},#{file_name},#{@counter},#{period}\n" exit end |
#loop_thread(sec) ⇒ Object
time loop
34 35 36 37 38 39 40 |
# File 'lib/shunkuntype/training.rb', line 34 def loop_thread(sec) Thread.start(sec) do |wait_time| sleep wait_time puts "\a Time up. Type return-key to finish.." @time_flag=false end end |
#print_keyboard ⇒ Object
print key positions
43 44 45 46 47 48 49 50 |
# File 'lib/shunkuntype/training.rb', line 43 def print_keyboard content = " q \\\\ w \\\\ e \\\\ r t \\\\ y u \\\\ i \\\\ o \\\\ p\na \\\\ s \\\\ d \\\\ f g \\\\ h j \\\\ k \\\\ l \\\\ ; enter\nsh z \\\\ x \\\\ c \\\\ v b \\\\ n m \\\\ , \\\\\\ . \\\\ shift\n" print content end |
#size_training(file_name, data, start_time) ⇒ Object
78 79 80 81 82 |
# File 'lib/shunkuntype/training.rb', line 78 def size_training(file_name,data,start_time) type_loop(data) exit_proc(start_time,file_name,(Time.now-start_time).to_i) return end |
#time_training(base_name, data, start_time) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/shunkuntype/training.rb', line 84 def time_training(base_name,data,start_time) loop_thread(@period) data2=[] 20.times{ data2 << data } type_loop(data2.flatten) keep_record(start_time,base_name,@period) end |
#type_loop(data) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/shunkuntype/training.rb', line 68 def type_loop(data) data.each do |sentence| break if @time_flag == false puts sentence p '' line=STDIN.gets.chomp counter(sentence,line) end end |