module RandomText
Constants
- DOWNCASE_TABLE
- OTHER_LOWER
- OTHER_UPPER
Public Class Methods
add_dictionary(path)
click to toggle source
# File lib/random_text.rb, line 14 def add_dictionary(path) const_name = classify(File.basename(path, File.extname(path))) dictionary = Dictionary.new(File.read(path)) self.const_set(const_name, dictionary) dictionaries[const_name] = dictionary end
classify(s)
click to toggle source
# File lib/random_text.rb, line 49 def classify(s) s.split('_').map(&:capitalize).join end
dictionaries()
click to toggle source
# File lib/random_text.rb, line 10 def dictionaries @dictionaries ||= {} end
downcase(s)
click to toggle source
# File lib/random_text.rb, line 57 def downcase(s) s.downcase.gsub(/./u){ |c| DOWNCASE_TABLE[c] || c } end
run(binary, args)
click to toggle source
# File lib/random_text.rb, line 21 def run(binary, args) arg = args.join(' ').strip.downcase arg = 'p' if arg.empty? if m = arg.match(/^(\d+)?\s*(p|w|s|u)/) number = m[1] && m[1].to_i dictionary = dictionaries[classify(binary)] puts case m[2] when 'p' number ? dictionary.paragraphs(number) : dictionary.paragraph when 's' number ? dictionary.sentences(number) : dictionary.sentence when 'w' number ? dictionary.words(number) : dictionary.word when 'u' number ? dictionary.uniq_words(number) : dictionary.uniq_words end else abort <<-help #{binary} [specifier] without specifier returns one paragraph p, paragraph, s, sentence, w, word - one paragraph, sentence, word X p, X paragraph, X s, X sentence, X w, X word - X paragraphs, sentences, words u, uniq_words - all words X u, X uniq_words - X uniq_words help end end