Class: MarkovDict

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeMarkovDict

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