class SuperHacker::CodeGenerator
CreateCode
Public Class Methods
new()
click to toggle source
# File lib/super_hacker.rb, line 106 def initialize end
Public Instance Methods
print_progres()
click to toggle source
プログレスバーの表示
# File lib/super_hacker.rb, line 124 def print_progres() 100.times do |num| print "#{num}%\r" sleep 0.025 STDOUT.flush end end
read_csv(file_name,sleep_time = 0.001,word_sleep = 0.02)
click to toggle source
CSVファイルの読み込み
# File lib/super_hacker.rb, line 133 def read_csv(file_name,sleep_time = 0.001,word_sleep = 0.02) csv_data = CSV.read(file_name, headers: true) csv_data.each do |data| #もしテキストがなければ改行して次の文字へ if data["text"].nil? puts next end #sleep_timeが設定されていれば、csvファイルのほうを有効にする if data["sleep_time"].nil? == false type_word_code(data["text"],word_sleep,data["sleep_time"].to_f) else #csvデータを表示する type_word_code(data["text"],word_sleep,sleep_time) end end end
type_word_code(str,split_sleep = 0.02,typing_sleep = 0.02)
click to toggle source
単語毎に区切って表示
# File lib/super_hacker.rb, line 109 def type_word_code(str,split_sleep = 0.02,typing_sleep = 0.02) str.chars do |s| #もし空白なら空白用のスリープ時間を適用 if s == ' ' || s == '\t' sleep(split_sleep) print s else sleep(typing_sleep) print s end end puts end