plasper 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/plasper.rb +67 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c9dab30a21d9405053621776dd381363c6a8b6a4
|
4
|
+
data.tar.gz: 2b8a981920244fbab33bca4a49354b7229a3309a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9eb119cd0aac2aa3983e8c2c1a9f7ced054bc15649f680971303a5f3ff5b3a4bde1613d84f59be1043df65d892bf183b088e5231b349ddbe904ff9fe5a6b8be0
|
7
|
+
data.tar.gz: b2f4c0f2c35b869a75109fdd944d01fdd592003dd83ba42fd9d974c81cbe822d2eb2b1707940b5248ab3f41a304db597a0d7e6a1fae37eb46cf5b0ce20d41fc7
|
data/lib/plasper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
class Plasper
|
2
|
+
attr_accessor :word_range, :sentence_range, :passage_range, :vowels, :consonants
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@word_range = { 1 => 1, 2 => 2, 3 => 3, 4 => 5, 5 => 5, 6 => 6, 7 => 4, 8 => 2, 9 => 1 }
|
6
|
+
@sentence_range = { 1 => 1, 2 => 1, 3 => 2, 4 => 2, 5 => 3, 6 => 4, 7 => 5, 8 => 4, 9 => 2 }
|
7
|
+
@passage_range = { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 3, 6 => 2, 7 => 1, 8 => 1, 9 => 1 }
|
8
|
+
@vowels = { e: 1, u: 1, i: 1, o: 1, a: 1 }
|
9
|
+
@consonants = {
|
10
|
+
q: 1, w: 1, r: 2, t: 2, y: 2, p: 2, s: 3, d: 3, f: 4, g: 3,
|
11
|
+
h: 3, j: 3, k: 3, l: 2, z: 1, x: 1, c: 2, v: 2, b: 2, n: 2, m: 2
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def word
|
16
|
+
word_length = weighted_select(@word_range).to_i
|
17
|
+
word, length = '', 0
|
18
|
+
while length < word_length
|
19
|
+
letter = rand(100) < 40 ? consonant : vowel
|
20
|
+
word += letter
|
21
|
+
length += 1
|
22
|
+
end
|
23
|
+
|
24
|
+
word
|
25
|
+
end
|
26
|
+
|
27
|
+
def sentence
|
28
|
+
sentence_length = weighted_select(@sentence_range).to_i
|
29
|
+
sentence, length = [], 0
|
30
|
+
while length < sentence_length
|
31
|
+
sentence << word
|
32
|
+
length += 1
|
33
|
+
end
|
34
|
+
|
35
|
+
sentence.join(' ').capitalize + '.'
|
36
|
+
end
|
37
|
+
|
38
|
+
def passage
|
39
|
+
passage_length = weighted_select(@passage_range).to_i
|
40
|
+
passage, length = [], 0
|
41
|
+
while length < passage_length
|
42
|
+
passage << sentence
|
43
|
+
length += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
passage.join(' ')
|
47
|
+
end
|
48
|
+
|
49
|
+
def vowel
|
50
|
+
weighted_select @vowels
|
51
|
+
end
|
52
|
+
|
53
|
+
def consonant
|
54
|
+
weighted_select @consonants
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def weighted_select(rules)
|
60
|
+
buffer = []
|
61
|
+
rules.each do |item, weight|
|
62
|
+
weight.times { buffer << item }
|
63
|
+
end
|
64
|
+
|
65
|
+
buffer.sample.to_s
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plasper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxim Khan-Magomedov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple abstract texts generator
|
14
|
+
email: maxim.km@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/plasper.rb
|
20
|
+
homepage: https://github.com/ozgg/plasper
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Plasper
|
44
|
+
test_files: []
|