Class: RandomText
- Inherits:
-
Object
- Object
- RandomText
- Defined in:
- lib/random_text.rb
Defined Under Namespace
Classes: Randomized
Instance Method Summary collapse
-
#initialize(*args) ⇒ RandomText
constructor
A new instance of RandomText.
- #sentence ⇒ Object
- #sentences(n) ⇒ Object
- #unique_words(n) ⇒ Object
- #word ⇒ Object
- #words(n) ⇒ Object
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
#sentence ⇒ Object
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 |
#word ⇒ Object
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 |