Class: MarkyMarkov::Dictionary
- Inherits:
-
TemporaryDictionary
- Object
- TemporaryDictionary
- MarkyMarkov::Dictionary
- Defined in:
- lib/marky_markov.rb
Instance Attribute Summary collapse
-
#dictionarylocation ⇒ Object
readonly
Open (or create if it doesn’t exist) a Persistent Markov Chain Dictionary and sentence generator for use.
Class Method Summary collapse
-
.delete_dictionary!(location) ⇒ Object
Takes a dictionary location/name and deletes it from the file-system.
Instance Method Summary collapse
-
#initialize(location, depth = 2) ⇒ Dictionary
constructor
A new instance of Dictionary.
-
#save_dictionary! ⇒ Object
Save the Persistent Dictionary file into JSON format for later use.
Methods inherited from TemporaryDictionary
#clear!, #dictionary, #generate_n_sentences, #generate_n_words, #method_missing, #parse_file, #parse_string, #respond_to_missing?
Constructor Details
#initialize(location, depth = 2) ⇒ Dictionary
Returns a new instance of Dictionary.
135 136 137 138 139 |
# File 'lib/marky_markov.rb', line 135 def initialize(location, depth=2) @dictionarylocation = "#{location}.mmd" @dictionary = PersistentDictionary.new(@dictionarylocation, depth) @sentence = MarkovSentenceGenerator.new(@dictionary) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MarkyMarkov::TemporaryDictionary
Instance Attribute Details
#dictionarylocation ⇒ Object (readonly)
Open (or create if it doesn’t exist) a Persistent Markov Chain Dictionary and sentence generator for use. Optional dictionary depth may be supplied.
134 135 136 |
# File 'lib/marky_markov.rb', line 134 def dictionarylocation @dictionarylocation end |
Class Method Details
.delete_dictionary!(location) ⇒ Object
To ensure that someone doesn’t pass in something that shouldn’t
Takes a dictionary location/name and deletes it from the file-system. Alternatively, pass in a MarkyMarkov::Dictionary object in directly and it will delete that objects dictionary from disk.
be deleted by accident, the filetype .mmd is added to the end of the supplied argument, so do not include the extension when calling the method.
162 163 164 165 |
# File 'lib/marky_markov.rb', line 162 def self.delete_dictionary!(location) location += ".mmd" if location.class == String PersistentDictionary.delete_dictionary!(location) end |
Instance Method Details
#save_dictionary! ⇒ Object
Save the Persistent Dictionary file into JSON format for later use.
145 146 147 |
# File 'lib/marky_markov.rb', line 145 def save_dictionary! @dictionary.save_dictionary! end |