Top Level Namespace

Defined Under Namespace

Classes: DictionaryMap, WordNode

Instance Method Summary collapse

Instance Method Details

#get_map(map, string = '') ⇒ Object

Collapses the map back into words. Failure of a comment above. Ammended: Returns a list of all words beginning with string. map should be the list of nodes succeeding in the Dictionary after the last character in string. For example, for all words in the dictionary, send dictionary.start_nodes only. For all words that start with x, call get_map (dictionary.start_nodes.successors, ‘x’)



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/dict_map.rb', line 155

def get_map(map, string = '')
    words = []
    if map.empty?
        puts "Error, made it to the end of string #{string} and found no end node."
        return words
    end
    new_string = nil
    map.each do |letter, node|
        new_string = string + letter
        if node.ends_word?
            words << new_string
        end
        if !node.successors.empty?
            words = words + get_map(node.successors, new_string) 
        end
    end
    return words 
end