Project

gold_mine

0.0
No commit activity in last 3 years
No release in over 3 years
A simple, fortune cookie library for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 2.14

Runtime

~> 1.1.4
 Project Readme

GoldMine

Gem Version

A simple, fortune cookie library for Ruby. GoldMine provides access to the contents of a fortune file. The fortune file is a database which contains fortunes ― funny, offensive, serious and reflective (very rarely) quotes, jokes, or poems. Example.

GoldMine allows to create and read a data file which describes the database. Such a file is called an index. The index always has the same name as the database, but ends with a ".dat" extension. The index created by GoldMine is compatible with a fortune program written by Ken Arnold.

Install

gem install gold_mine

or add this to your Gemfile:

gem "gold_mine"

and run bundle install command.

Getting Started

Create a GoldMine::DB instance that points to a fortune file. After that you have access to that collection via a few methods.

db = GoldMine::DB.new(path: "/home/user/fortunes")
puts db.random # Throws a random fortune
puts db.fortunes # Returns all fortunes

If you don't pass the file path, GoldMine will use default fortunes database which was prepared by Brian M. Clapper.

Options

By passing comments: true option you specify that your fortunes collection includes comments. A comment is identified as a double delimiter at the begging of the line.

You could also define a delimiter by passing delim: "character" option. The default delimiter is a percent sign.

GoldMine::DB.new(path: "/my/fortunes/path", comments: true, delim: "#")

Database with an index

If you need to access the database using the index, use GoldMine::IDB class.

GoldMine::IDB.new(path: "/my/fortunes/path")

You can't pass options to GoldMine::IDB because all options are extracted from the index file.

Fortune

An instance of GoldMine::Fortune class represents a single fortune. Wherever GoldMine returns a single fortune or bundle of them in fact it returns GoldMine::Fortune instances.

fortune = GoldMine::DB.new.random
fortune.content # Returns a body of the fortune
fortune.attribution # Returns an attribution if exists

Create an index

You can pass many options when creating an instance. To learn about all the possibilities, please see the documentation.

writer = GoldMine::IndexWriter.new("/path/to/database")
writer.write

Ideas & bugs

Please submit to issues.

License

"THE BEER-WARE LICENSE" (Revision 42): Marcin "Archetylator" Syngajewski wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.