How it Works
The book's table of contents and chapters are stored in individual documents within a data directory. A before block uses File#readlines to store the table of contents in an instance variable representing an array. They are iterated through, using the index of each chapter to link to that chapter page in the menu. File#read likewise uses the chapter indices to pull their texts from the corresponding file and stores them in another instance variable. A helper method splits chapters into paragraphs using \n\n as a delimiter.
- A search bar allows users to retrieve individual paragraphs from the book containing the query term. Matching paragraphs are stored in a hash, and the entire paragraph is displayed to the user as a link back to that chapter. The paragraph index is used to anchor the link to the exact spot in the chapter.
- Sinatra::reloader allows the main application file to reload without restarting the app, but only in development to avoid disruptions in production.
- The app is run on the Sinatra DSL/library and hosted on Heroku.
- Procfile and config.ru files direct the webserver in the start-up process and specify Puma as the webserver instead of WEBrick.
- I worked on this app quite a while ago, early in my studies. At that time, nested lists and iterations were bit confusing. The File methods and splitting paragraphs with \n\n were also new to me at that time.
- One of my planned upgrades is to let the user upload books of their choosing. First, I have to figure out how to parse PDFs and similar files into text so that they are compatible with the File methods driving the app.