Class: GPLType::TypingLine

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

Overview

TypingLine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(answer) ⇒ TypingLine

Returns a new instance of TypingLine.



416
417
418
419
# File 'lib/curses_color.rb', line 416

def initialize(answer)
  @entered = ""
  @answer = answer
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



455
456
457
# File 'lib/curses_color.rb', line 455

def answer
  @answer
end

#enteredObject (readonly)

Returns the value of attribute entered.



455
456
457
# File 'lib/curses_color.rb', line 455

def entered
  @entered
end

Instance Method Details

#append(window, c) ⇒ Object



432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/curses_color.rb', line 432

def append(window, c)
  c = c.chr if c.is_a?(Integer)
  @entered << c
  mistype = @answer[@entered.size-1].chr != c
  if mistype && c == " "
    window.addstr(" ", :wrong_space)
  else
    window.addstr(c, mistype ? :wrong : :ok)
  end
  window.refresh

  mistype
end

#backspace(window) ⇒ Object



425
426
427
428
429
430
# File 'lib/curses_color.rb', line 425

def backspace(window)
  @entered = @entered[0...(@entered.size-1)]
  window.setpos(window.cury, window.curx - 1)
  window.delch
  window.refresh
end

#colObject



421
422
423
# File 'lib/curses_color.rb', line 421

def col
  @entered.size
end

#correct?Boolean

Returns:

  • (Boolean)


451
452
453
# File 'lib/curses_color.rb', line 451

def correct?
  @entered == @answer
end

#next_line(answer) ⇒ Object



446
447
448
449
# File 'lib/curses_color.rb', line 446

def next_line(answer)
  @entered = ""
  @answer = answer
end