Class: MarkovWords::Generator
- Inherits:
-
Object
- Object
- MarkovWords::Generator
- Defined in:
- lib/markov_words/generator.rb
Overview
This class takes care of word generation, and will store the database into
a FileStore
object.
Instance Attribute Summary collapse
-
#data_store ⇒ Object
readonly
It's useful to be able to access the data store object directly, for example if you were to want to implement storage of related metadata into the same storage system that holds the database.
Instance Method Summary collapse
-
#grams ⇒ Hash
The current database of n-gram mappings.
-
#initialize(opts = {}) ⇒ Words
constructor
Create a new "Words" object.
-
#word ⇒ String
Generate a new word.
Constructor Details
#initialize(opts = {}) ⇒ Words
Create a new "Words" object
39 40 41 42 43 44 45 46 |
# File 'lib/markov_words/generator.rb', line 39 def initialize(opts = {}) @grams = nil @gram_size = opts.fetch :gram_size, 2 @max_length = opts.fetch :max_length, 16 @min_length = opts.fetch :min_length, 3 initialize_data(opts) end |
Instance Attribute Details
#data_store ⇒ Object (readonly)
It's useful to be able to access the data store object directly, for example if you were to want to implement storage of related metadata into the same storage system that holds the database.
10 11 12 |
# File 'lib/markov_words/generator.rb', line 10 def data_store @data_store end |
Instance Method Details
#grams ⇒ Hash
The current database of n-gram mappings
14 15 16 17 18 19 20 21 |
# File 'lib/markov_words/generator.rb', line 14 def grams if @grams.nil? @grams = @data_store.retrieve_data(:grams) || markov_corpus(@corpus_file, @gram_size) else @grams end end |
#word ⇒ String
Generate a new word
50 51 52 |
# File 'lib/markov_words/generator.rb', line 50 def word generate_word end |