Call WellReadFaker.paragraph
to get a random paragraph. For example,
following piece of code:
puts WellReadFaker.paragraph
Could print (without newlines):
Thus they prayed, but not as yet would Jove grant them their prayer. Then Priam, descendant of Dardanus, spoke, saying, "Hear me, Trojans and Achaeans, I will now go back to the wind-beaten city of Ilius: I dare not with my own eyes witness this fight between my son and Menelaus, for Jove and the other immortals alone know which shall fall."
Well Read Faker comes with "Iliad" bundled as a default source. However, custom sources can be used:
WellReadFaker.add_source :book_in_my_language, "path/to/book", {}
WellReadFaker[:book_in_my_language].paragraph
WellReadFaker.default_source = :book_in_my_language
WellReadFaker.paragraph
WellReadFaker[:iliad].paragraph # Iliad can be still accessed
The second argument passed to WellReadFaker::add_source
can be a string
containing a file path, or any object which responds to #read
, like File
instance.
The third argument is optional but can be used to supply additional options,
for example to skip book descriptor or legal notes. See
lib/well_read_faker/load_bundled_sources.rb
for examples.
In the source text, paragraphs must be separated with blank lines.
For given text source, the paragraphs are returned in a random order, but will
not be repeated (in the sense of String#==
equality) until all unique
paragraphs from that text are returned exactly once. After that, they are
returned once again in the same order.
Therefore it is guaranteed that if given source text contains n
unique
paragraphs, then n
subsequent calls of #paragraph
method will return
unique values.
For your information, The Iliad contains over 1000 unique paragraphs.
The gem is available as open source under the terms of the MIT License.
The gem includes "Iliad", a classical masterpiece by Homer, translated to English by Samuel Butler. A work is in public domain in USA and in almost whole world (if not whole world) as the translator has died over 100 years ago (not to mention the original author). It has been downloaded from Project Gutenberg, more details about the work can be found there.