class Dutchman::GhostWriter::TypingSpeed

Attributes

humanize[R]
name[R]

Public Class Methods

new(name,humanize) click to toggle source
# File lib/dutchman/ghost_writer/typing_speed.rb, line 6
def initialize(name,humanize)
  @name = name
  @humanize = humanize
end

Public Instance Methods

available_speeds() click to toggle source
# File lib/dutchman/ghost_writer/typing_speed.rb, line 32
def available_speeds
  @avaliable_speeds ||= begin
    hash = { slow: wpm_to_cps(23.0),
      moderate: wpm_to_cps(35.0),
      fast: wpm_to_cps(50.0) }
    hash.default = hash[:moderate]
    hash
  end
end
delay_between_characters() click to toggle source

The value in milliseconds to wait between characters

# File lib/dutchman/ghost_writer/typing_speed.rb, line 18
def delay_between_characters
 standard_delay = (1.0 / available_speeds[name]).round(2)
 current_delay = standard_delay + variance(standard_delay)
 current_delay.round(2)
end
random_number_between_pos_and_neg(number) click to toggle source
# File lib/dutchman/ghost_writer/typing_speed.rb, line 28
def random_number_between_pos_and_neg(number)
  rand(number * 100).to_f / 100 * (rand(2).odd? ? -1 : 1)
end
variance(delay) click to toggle source
# File lib/dutchman/ghost_writer/typing_speed.rb, line 24
def variance(delay)
  humanize ? random_number_between_pos_and_neg(delay) : 0.0
end
wpm_to_cps(wpm) click to toggle source

The assumption is that each word is 8 characters in length.

# File lib/dutchman/ghost_writer/typing_speed.rb, line 45
def wpm_to_cps(wpm)
  wpm.to_f * 10.0 / 60.0
end