Class: GPLType::TypingLine
- Inherits:
-
Object
- Object
- GPLType::TypingLine
- Defined in:
- lib/curses_color.rb
Overview
TypingLine
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#entered ⇒ Object
readonly
Returns the value of attribute entered.
Instance Method Summary collapse
- #append(window, c) ⇒ Object
- #backspace(window) ⇒ Object
- #col ⇒ Object
- #correct? ⇒ Boolean
-
#initialize(answer) ⇒ TypingLine
constructor
A new instance of TypingLine.
- #next_line(answer) ⇒ Object
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
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
455 456 457 |
# File 'lib/curses_color.rb', line 455 def answer @answer end |
#entered ⇒ Object (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 |
#col ⇒ Object
421 422 423 |
# File 'lib/curses_color.rb', line 421 def col @entered.size end |
#correct? ⇒ 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 |