Class: GoldMine::DB
- Inherits:
-
Object
- Object
- GoldMine::DB
- Defined in:
- lib/gold_mine/db.rb
Overview
Database of fortunes.
Example:
db = DB.new(path: "/home/user/fortunes")
db.random # => random fortune
Options:
- :
path
-
The path of database.
- :
comments
-
Pass true if allow comments is needed.
- :
delim
-
The character which is used as delimiter in a database.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #fortunes ⇒ Object
-
#initialize(options = {}) ⇒ DB
constructor
A new instance of DB.
- #random ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DB
Returns a new instance of DB.
28 29 30 31 |
# File 'lib/gold_mine/db.rb', line 28 def initialize( = {}) @path = .fetch(:path, GoldMine.default_db_path) @options = self.class..merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/gold_mine/db.rb', line 26 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/gold_mine/db.rb', line 26 def path @path end |
Class Method Details
.default_options ⇒ Object
20 21 22 23 24 |
# File 'lib/gold_mine/db.rb', line 20 def self. @default_options ||= { delim: "%" } end |
Instance Method Details
#fortunes ⇒ Object
37 38 39 |
# File 'lib/gold_mine/db.rb', line 37 def fortunes @fortunes ||= read_fortunes end |
#random ⇒ Object
33 34 35 |
# File 'lib/gold_mine/db.rb', line 33 def random fortunes.sample end |