Class: RandomText

Inherits:
Object
  • Object
show all
Defined in:
lib/random_text.rb

Defined Under Namespace

Classes: Randomized

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RandomText

Returns a new instance of RandomText.



22
23
24
25
26
# File 'lib/random_text.rb', line 22

def initialize(*args)
  data = [*args].flatten.join(' ')
  @words = Randomized.new(data.scan(/\w{4,}/).collect{ |w| w.chars.downcase.to_s }.uniq.map(&:chars))
  @sentences = Randomized.new(data.scan(/\S[^.]*\./m).uniq)
end

Instance Method Details

#sentenceObject



40
41
42
# File 'lib/random_text.rb', line 40

def sentence
  @sentences.get
end

#sentences(n) ⇒ Object



44
45
46
# File 'lib/random_text.rb', line 44

def sentences(n)
  Array.new(n){ sentence }.join(' ')
end

#unique_words(n) ⇒ Object



36
37
38
# File 'lib/random_text.rb', line 36

def unique_words(n)
  @words.unique(n)
end

#wordObject



28
29
30
# File 'lib/random_text.rb', line 28

def word
  @words.get
end

#words(n) ⇒ Object



32
33
34
# File 'lib/random_text.rb', line 32

def words(n)
  Array.new(n){ word }.join(' ').capitalize
end