class CW::CommonWords
Public Class Methods
new()
click to toggle source
# File lib/cw/common_words.rb, line 7 def initialize @words = [] end
Public Instance Methods
all()
click to toggle source
# File lib/cw/common_words.rb, line 34 def all File.foreach(dictionary).collect do |line| line.chomp end end
custom_dict_dir()
click to toggle source
# File lib/cw/common_words.rb, line 11 def custom_dict_dir File.join(WORK_DIR, Cfg.config["dictionary_dir"]) end
dict_filename()
click to toggle source
# File lib/cw/common_words.rb, line 22 def dict_filename @dict_filename ||= Cfg.config["dictionary_name"] ? Cfg.config["dictionary_name"] : DICT_FILENAME end
dictionary()
click to toggle source
# File lib/cw/common_words.rb, line 29 def dictionary @dictionary ||= File.join(dictionary_dir, dict_filename) end
dictionary_dir()
click to toggle source
# File lib/cw/common_words.rb, line 15 def dictionary_dir @dictionary_dir ||= Cfg.config["dictionary_dir"] ? custom_dict_dir : DICT_DIR end
low(last)
click to toggle source
# File lib/cw/common_words.rb, line 40 def low last results = [] count = 0 File.foreach(dictionary).collect do |line| if count <= last results << line.chomp end count += 1 break if count > last end results end
mid(first, last)
click to toggle source
# File lib/cw/common_words.rb, line 53 def mid first, last results = [] count = 0 File.foreach(dictionary).collect do |line| if (count >= first) && (count <= last) results << line.chomp end count += 1 break if count > last end results end
parse_quantity(quantity = :default)
click to toggle source
# File lib/cw/common_words.rb, line 66 def parse_quantity(quantity = :default) if quantity == :default return [0, 999] elsif quantity.class == 1.class [0, quantity - 1] (0...quantity).collect {|q| q} elsif quantity.class == Range ary = quantity.to_a return ary[0] - 1, ary[-1] -1 # ary.pop # ary.unshift ary[0] - 1 # ary end end
read(quantity = :default)
click to toggle source
# File lib/cw/common_words.rb, line 81 def read(quantity = :default) if quantity == :all @words = all else qty = parse_quantity(quantity) if qty[0] == 0 @words = low qty[-1] else @words = mid qty[0], qty[1] end end @words end
to_a()
click to toggle source
# File lib/cw/common_words.rb, line 95 def to_a @words end