class SpeedCheck

Attributes

number[R]
period[R]

Public Class Methods

new() click to toggle source
# File lib/shunkuntype/speed.rb, line 15
def initialize
  @number = 20 #default 20
  @period = 60
  check_data_files
  data = mk_random_words
  t0,t1,count = exec_speed_check(data)
  keep_record(t0,t1,count)
end

Public Instance Methods

check_data_files() click to toggle source
# File lib/shunkuntype/speed.rb, line 24
def check_data_files
  begin
    file=open(Shunkuntype::SPEED_FILE,"r")
    if file
      puts "#{Shunkuntype::SPEED_FILE} opened succcessfully"
    end
  rescue
    puts "#{Shunkuntype::SPEED_FILE} does not exist in this directory. --init or try in another dir."
    exit
  end
end
exec_speed_check(data) click to toggle source
# File lib/shunkuntype/speed.rb, line 49
def exec_speed_check(data)
  print "\n\n"+number.to_s+" words should be cleared."
  print "\nType return-key to start."
  p ''
  line=$stdin.gets

  t0=Time.now
  count=0
  @number.times do |i|
    print_keyboard()
    puts (i+1).to_s
    word = data[i]
    count+=word.length
    while line!=word do
      puts word
      p ''
      line=$stdin.gets.chomp
    end
  end
  t1=Time.now
  return t0,t1,count
end
keep_record(t0,t1,count) click to toggle source
# File lib/shunkuntype/speed.rb, line 72
def keep_record(t0,t1,count)
  statement = t0.to_s+","
  statement << @number.to_s+","
  statement << (t1-t0).to_s+","
  icount=@period/(t1-t0)*count
  statement << icount.to_s+"\n"
  data_file=open(Shunkuntype::SPEED_FILE,"a+")
  data_file << statement
  p statement

  printf("%5.3f sec\n",Time.now-t0)
  printf("%4d characters.\n",icount)
end
mk_random_words() click to toggle source
# File lib/shunkuntype/speed.rb, line 35
def mk_random_words
  data=[]
  data_dir=File.expand_path('../../../lib/data', __FILE__)
  file=open("#{data_dir}/word.list",'r')
  while word=file.gets do
    data << word.chomp
  end
  data.shuffle!
  data.each do |word|
    print word+" "
  end
  return data
end
print_keyboard() click to toggle source

print key positions