class Flickollage::Dictionary
Constants
- COMMON_DICT_PATHS
- MAX_DICT_LENGTH
Attributes
words[R]
Public Class Methods
new(path_or_words)
click to toggle source
# File lib/flickollage/dictionary.rb, line 14 def initialize(path_or_words) @words = [] load_from_file(path_or_words) if path_or_words.is_a?(String) @words = path_or_words.reverse if path_or_words.is_a?(Array) end
Private Class Methods
default_dict_path()
click to toggle source
# File lib/flickollage/dictionary.rb, line 42 def default_dict_path COMMON_DICT_PATHS.find { |path| File.exist?(path) } || COMMON_DICT_PATHS.first end
Public Instance Methods
append(words)
click to toggle source
# File lib/flickollage/dictionary.rb, line 24 def append(words) @words += words.reverse end
pop()
click to toggle source
# File lib/flickollage/dictionary.rb, line 20 def pop @words.pop end
Private Instance Methods
load_from_file(path)
click to toggle source
# File lib/flickollage/dictionary.rb, line 30 def load_from_file(path) File.foreach(path).with_index do |line, i| break if i >= MAX_DICT_LENGTH line = line.chop @words << line unless line.empty? end @words.shuffle! rescue Errno::ENOENT raise Error, 'Dictionary file not found' end