Class: Teletype::Practice

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

Overview

Initializes screen size and click stats, then start the practice page by page.

Instance Method Summary collapse

Constructor Details

#initialize(text, height: 5, width: 120) ⇒ Practice

Returns a new instance of Practice.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/teletype/practice.rb', line 6

def initialize(text, height: 5, width: 120)
  @screen = Screen.new(height: height, width: width)
  @stats = Stats.new

  @lines = []
  text.each_line do |line|
    line.chars.each_slice(@screen.width) do |slice|
      @lines << slice.join
    end
  end

  @pager = Pager.new(@lines, @stats, @screen.height)
end

Instance Method Details

#startObject



20
21
22
23
24
25
26
# File 'lib/teletype/practice.rb', line 20

def start
  at_exit { @stats.save }

  @pager.each do |lines|
    Page.new(lines, @screen, @stats).run
  end
end