class WordGenerator::WordList
Constants
- FILE_PATH
- VALID_WORD_REGEX
Public Class Methods
contains?(word)
click to toggle source
# File lib/word_generator/word_list.rb, line 6 def self.contains?(word) data_source = WordGenerator.configuration.data_source !list(data_source: data_source)[word].nil? end
list(data_source: :file)
click to toggle source
# File lib/word_generator/word_list.rb, line 11 def self.list(data_source: :file) return [] unless data_source == :file @list_of_words ||= read_words_from_file end
Private Class Methods
read_words_from_file()
click to toggle source
# File lib/word_generator/word_list.rb, line 18 def self.read_words_from_file path = File.expand_path("../#{FILE_PATH}", File.dirname(__dir__)) File.foreach(path).with_object({}) do |line, result| word = line.chomp! result[word] = 1 if VALID_WORD_REGEX.match?(word) end end