View Source Fortune (fortune v0.1.1)
Get a fortune!
Fortune reads a string, usually a random one, from one or more fortune files. Fortune files contain a list of strings and an associated index for for quick retrieval of a randomly chosen string. This implementation provides an Elixir take on the ubiquitous Unix fortune implementation. It is compatible with Unix fortune and can read most Unix fortune files.
iex> Fortune.random()
{:ok, "Harness the power of the BEAM, one Elixir potion at a time."}No fortunes are provided, though. You'll need to add your own, add Elixir libraries to your mix dependencies that have fortunes, or use your system's fortunes.
Fortunes provided by Elixir libraries are stored in that library's
priv/fortune directory. See the README.md for using the :fortune_compiler
for adding your own.
If no Elixir-provided fortunes are found, fortune checks the system's
/usr/share/games/fortune directory (and various similar ones) for fortunes
to find something.
See fortune_options/0 for modifying fortune search paths.
Summary
Types
Fortune options
Functions
Return statistics on fortunes
Return a random fortune
Return a random fortune or raise an exception
Types
@type fortune_options() :: [ paths: String.t() | [String.t()] | nil, included_applications: atom() | [atom()] | nil, excluded_applications: atom() | [atom()] | nil ]
Fortune options
Pass these to Fortune.random/1 and similar functions:
:paths- a list of absolute paths tofortunedirectories or files. Overrides other options:included_applications- specifically include these applications that contain fortunes:excluded_applications- exclude these applications from being scanned for fortunes:include_system_fortunes?- set totrueto include system fortunes. Defaults totrueif no Elixir projects supply fortunes.
To set defaults for your project, add Fortune options to your application's config.exs:
config :fortune, include_system_fortunes?: true
Functions
@spec info(fortune_options()) :: {:ok, map()} | {:error, atom()}
Return statistics on fortunes
This can be useful for finding out what fortunes are available. The options are
the same as the ones for random/1.
NOTE: The returned map may change in the future which is why it is untyped.
@spec random(fortune_options()) :: {:ok, String.t()} | {:error, atom()}
Return a random fortune
See Fortune for an overview and fortune_options/0 for modifying fortune
search paths.
@spec random!(fortune_options()) :: String.t()
Return a random fortune or raise an exception
See Fortune for an overview and fortune_options/0 for modifying fortune
search paths.