class RandomText::Dictionary

Public Class Methods

new(text) click to toggle source
# File lib/random_text/dictionary.rb, line 3
def initialize(text)
  @words = RandomStrings.new(text.scan(/\w{3,}/u).
          collect{ |w| RandomText.downcase(w) }.
          reject{ |w| w =~ /^[0-9]/u }.
          uniq.map{ |w| w })
  @sentences = RandomStrings.new(text.split(/[\r\n]+/u).
          map(&:strip).compact.
          delete_if(&:empty?).uniq)
end

Public Instance Methods

paragraph() click to toggle source
# File lib/random_text/dictionary.rb, line 34
def paragraph
  @sentences.get(5).join(' ')
end
paragraphs(n) click to toggle source
# File lib/random_text/dictionary.rb, line 38
def paragraphs(n)
  Array.new(n){ paragraph }
end
sentence() click to toggle source
# File lib/random_text/dictionary.rb, line 26
def sentence
  @sentences.get
end
sentences(n = :all) click to toggle source
# File lib/random_text/dictionary.rb, line 30
def sentences(n = :all)
  @sentences.get(n)
end
uniq_words(n = :all) click to toggle source
# File lib/random_text/dictionary.rb, line 21
def uniq_words(n = :all)
  @words.uniq(n)
end
Also aliased as: unique_words
unique_words(n = :all)
Alias for: uniq_words
word() click to toggle source
# File lib/random_text/dictionary.rb, line 13
def word
  @words.get
end
words(n = :all) click to toggle source
# File lib/random_text/dictionary.rb, line 17
def words(n = :all)
  @words.get(n)
end