Here we look at how we can read a book with CW.

Book Reading

Book reading can be helpful with improving comprehension when learning and practicing CW. It is one thing to be able to copy the code - but another to be able to comprehend the content at the same time. As you progress through the book, a bookmark is made by CW so that you will continue where you left off the next time you read the book.

read_book command

To read a book, you use the read_book command. The following parameters can be passed to the book reader:

  • sentences
  • duration

Even without supplying your own books, CW comes pre-loaded with a book to read:

Read two sentences

  require "cw"

# book_reading.rb

cw do
  comment 'read two sentences of book (18 wpm, 12 ewpm)'
  wpm 18
  ewpm 12
  read_book(sentences: 2)
end


Read book for one minute

  require "cw"

# book_reading_2.rb

cw do
  comment 'read book for one minute (18 wpm, 12 ewpm)'
  wpm 18
  ewpm 12
  read_book(duration: 1)
  print_words
end



Read your own books

If you wish to read your own books, create a directory called books in your working directory, and put your books in there. For instance you could create the small book shown below and place in the books directory:

  This is my book to read.
The end.


You can then read the book as follows:

  require "cw"

# book_reading_3.rb

cw do
  book_name "book_to_read.txt"
  wpm 18
  ewpm 12
  read_book(sentences: 1)
end



Specify the book directory

In addition you can specify a different book directory as follows:

  require "cw"

# book_reading_4.rb

cw do
  book_dir "data/text/"
  book_name "book.txt"
  wpm 18
  ewpm 12
  read_book(sentences: 2)
end



Test-by-letter book reading

By default the book reader tests-by-word. You can however choose to test-by-letter by setting the output parameter to letter:

  require "cw"

# book_reading_5.rb

cw do
  wpm 18
  ewpm 12
  comment 'read book (2 sentences, test-by-letter)'
  read_book(sentences: 1, output: :letter)
end