Class: MarkovDict
- Inherits:
-
Object
- Object
- MarkovDict
- Defined in:
- lib/markov_namegen/markov_namegen.rb
Overview
Creates a dictionary with prefixes as keys, and an array of possible suffixes as values, to be used by MarkovNameGen class
Instance Method Summary collapse
- #add_key(prefix, suffix) ⇒ Object
- #fetch_suffix(prefix) ⇒ Object
-
#initialize ⇒ MarkovDict
constructor
A new instance of MarkovDict.
Constructor Details
#initialize ⇒ MarkovDict
Returns a new instance of MarkovDict.
6 7 8 |
# File 'lib/markov_namegen/markov_namegen.rb', line 6 def initialize @dict = {} end |
Instance Method Details
#add_key(prefix, suffix) ⇒ Object
10 11 12 |
# File 'lib/markov_namegen/markov_namegen.rb', line 10 def add_key(prefix, suffix) @dict.include?(prefix) ? @dict[prefix].push(suffix) : @dict[prefix] = [suffix] end |
#fetch_suffix(prefix) ⇒ Object
14 15 16 |
# File 'lib/markov_namegen/markov_namegen.rb', line 14 def fetch_suffix(prefix) @dict[prefix].sample end |