Class: Plasper
- Inherits:
-
Object
- Object
- Plasper
- Defined in:
- lib/plasper.rb
Instance Attribute Summary collapse
-
#consonants ⇒ Object
Returns the value of attribute consonants.
-
#passage_range ⇒ Object
Returns the value of attribute passage_range.
-
#sentence_range ⇒ Object
Returns the value of attribute sentence_range.
-
#vowels ⇒ Object
Returns the value of attribute vowels.
-
#word_range ⇒ Object
Returns the value of attribute word_range.
Instance Method Summary collapse
- #consonant ⇒ Object
-
#initialize ⇒ Plasper
constructor
A new instance of Plasper.
- #passage ⇒ Object
- #sentence ⇒ Object
- #vowel ⇒ Object
- #word ⇒ Object
Constructor Details
#initialize ⇒ Plasper
Returns a new instance of Plasper.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/plasper.rb', line 4 def initialize @word_range = { 1 => 1, 2 => 2, 3 => 3, 4 => 5, 5 => 5, 6 => 6, 7 => 4, 8 => 2, 9 => 1 } @sentence_range = { 1 => 1, 2 => 1, 3 => 2, 4 => 2, 5 => 3, 6 => 4, 7 => 5, 8 => 4, 9 => 2 } @passage_range = { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 3, 6 => 2, 7 => 1, 8 => 1, 9 => 1 } @vowels = { e: 1, u: 1, i: 1, o: 1, a: 1 } @consonants = { q: 1, w: 1, r: 2, t: 2, y: 2, p: 2, s: 3, d: 3, f: 4, g: 3, h: 3, j: 3, k: 3, l: 2, z: 1, x: 1, c: 2, v: 2, b: 2, n: 2, m: 2 } end |
Instance Attribute Details
#consonants ⇒ Object
Returns the value of attribute consonants.
2 3 4 |
# File 'lib/plasper.rb', line 2 def consonants @consonants end |
#passage_range ⇒ Object
Returns the value of attribute passage_range.
2 3 4 |
# File 'lib/plasper.rb', line 2 def passage_range @passage_range end |
#sentence_range ⇒ Object
Returns the value of attribute sentence_range.
2 3 4 |
# File 'lib/plasper.rb', line 2 def sentence_range @sentence_range end |
#vowels ⇒ Object
Returns the value of attribute vowels.
2 3 4 |
# File 'lib/plasper.rb', line 2 def vowels @vowels end |
#word_range ⇒ Object
Returns the value of attribute word_range.
2 3 4 |
# File 'lib/plasper.rb', line 2 def word_range @word_range end |
Instance Method Details
#consonant ⇒ Object
53 54 55 |
# File 'lib/plasper.rb', line 53 def consonant weighted_select @consonants end |
#passage ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plasper.rb', line 38 def passage passage_length = weighted_select(@passage_range).to_i passage, length = [], 0 while length < passage_length passage << sentence length += 1 end passage.join(' ') end |
#sentence ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/plasper.rb', line 27 def sentence sentence_length = weighted_select(@sentence_range).to_i sentence, length = [], 0 while length < sentence_length sentence << word length += 1 end sentence.join(' ').capitalize + '.' end |
#vowel ⇒ Object
49 50 51 |
# File 'lib/plasper.rb', line 49 def vowel weighted_select @vowels end |
#word ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/plasper.rb', line 15 def word word_length = weighted_select(@word_range).to_i word, length = '', 0 while length < word_length letter = rand(100) < 40 ? consonant : vowel word += letter length += 1 end word end |