random-words 1.0.4
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/.irbrc +4 -0
- data/.rspec +4 -0
- data/.rspec_status +39 -0
- data/.rubocop.yml +64 -0
- data/CHANGELOG.md +29 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +111 -0
- data/README.md +90 -0
- data/Rakefile +85 -0
- data/bin/randw +334 -0
- data/lib/random-words/generator.rb +533 -0
- data/lib/random-words/string.rb +56 -0
- data/lib/random-words/version.rb +4 -0
- data/lib/random-words/words/bacon/adjectives.txt +329 -0
- data/lib/random-words/words/bacon/adverbs.txt +69 -0
- data/lib/random-words/words/bacon/articles-plural.txt +10 -0
- data/lib/random-words/words/bacon/articles-singular.txt +10 -0
- data/lib/random-words/words/bacon/clauses.txt +639 -0
- data/lib/random-words/words/bacon/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/bacon/nouns-plural.txt +168 -0
- data/lib/random-words/words/bacon/nouns-singular.txt +200 -0
- data/lib/random-words/words/bacon/numbers.txt +21 -0
- data/lib/random-words/words/bacon/verbs-passive.txt +105 -0
- data/lib/random-words/words/bacon/verbs-plural.txt +154 -0
- data/lib/random-words/words/bacon/verbs-singular.txt +106 -0
- data/lib/random-words/words/corporate/adjectives.txt +196 -0
- data/lib/random-words/words/corporate/adverbs.txt +462 -0
- data/lib/random-words/words/corporate/articles-plural.txt +10 -0
- data/lib/random-words/words/corporate/articles-singular.txt +10 -0
- data/lib/random-words/words/corporate/clauses.txt +101 -0
- data/lib/random-words/words/corporate/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/corporate/nouns-plural.txt +321 -0
- data/lib/random-words/words/corporate/nouns-singular.txt +474 -0
- data/lib/random-words/words/corporate/numbers.txt +21 -0
- data/lib/random-words/words/corporate/verbs-passive.txt +495 -0
- data/lib/random-words/words/corporate/verbs-plural.txt +173 -0
- data/lib/random-words/words/corporate/verbs-singular.txt +146 -0
- data/lib/random-words/words/english/adjectives.txt +325 -0
- data/lib/random-words/words/english/adverbs.txt +462 -0
- data/lib/random-words/words/english/articles-plural.txt +10 -0
- data/lib/random-words/words/english/articles-singular.txt +10 -0
- data/lib/random-words/words/english/clauses.txt +639 -0
- data/lib/random-words/words/english/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/english/nouns-plural.txt +524 -0
- data/lib/random-words/words/english/nouns-singular.txt +530 -0
- data/lib/random-words/words/english/numbers.txt +21 -0
- data/lib/random-words/words/english/verbs-passive.txt +495 -0
- data/lib/random-words/words/english/verbs-plural.txt +325 -0
- data/lib/random-words/words/english/verbs-singular.txt +350 -0
- data/lib/random-words/words/latin/adjectives.txt +188 -0
- data/lib/random-words/words/latin/adverbs.txt +212 -0
- data/lib/random-words/words/latin/articles-plural.txt +122 -0
- data/lib/random-words/words/latin/articles-singular.txt +19 -0
- data/lib/random-words/words/latin/clauses.txt +89 -0
- data/lib/random-words/words/latin/conjunctions-subordinate.txt +104 -0
- data/lib/random-words/words/latin/nouns-plural.txt +190 -0
- data/lib/random-words/words/latin/nouns-singular.txt +193 -0
- data/lib/random-words/words/latin/numbers.txt +21 -0
- data/lib/random-words/words/latin/verbs-passive.txt +171 -0
- data/lib/random-words/words/latin/verbs-plural.txt +177 -0
- data/lib/random-words/words/latin/verbs-singular.txt +218 -0
- data/lib/random-words.rb +6 -0
- data/random-words.gemspec +36 -0
- data/src/_README.md +92 -0
- metadata +119 -0
data/bin/randw
ADDED
@@ -0,0 +1,334 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/random-words'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
module RandomWords
|
8
|
+
class Terminal
|
9
|
+
def initialize(source = :english)
|
10
|
+
# Create an instance of the generator
|
11
|
+
@sentence_generator = RandomWords::Generator.new(source)
|
12
|
+
@colors = {
|
13
|
+
text: :yellow,
|
14
|
+
counter: :boldcyan,
|
15
|
+
marker: :boldgreen,
|
16
|
+
bracket: :cyan
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def colors
|
21
|
+
{
|
22
|
+
black: 30,
|
23
|
+
red: 31,
|
24
|
+
green: 32,
|
25
|
+
yellow: 33,
|
26
|
+
blue: 34,
|
27
|
+
magenta: 35,
|
28
|
+
cyan: 36,
|
29
|
+
white: 37,
|
30
|
+
boldblack: '1;30',
|
31
|
+
boldred: '1;31',
|
32
|
+
boldgreen: '1;32',
|
33
|
+
boldyellow: '1;33',
|
34
|
+
boldblue: '1;34',
|
35
|
+
boldmagenta: '1;35',
|
36
|
+
boldcyan: '1;36',
|
37
|
+
boldwhite: '1;37',
|
38
|
+
reset: 0
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def colorize_text(text, color)
|
43
|
+
color_code = colors[color]
|
44
|
+
|
45
|
+
"\e[#{color_code}m#{text}\e[0m"
|
46
|
+
end
|
47
|
+
|
48
|
+
def header_1(text)
|
49
|
+
puts colorize_text("\n\n#{text}", :boldgreen)
|
50
|
+
puts colorize_text('=' * text.length, :boldgreen)
|
51
|
+
puts "\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
def header_2(text)
|
55
|
+
puts colorize_text("\n\n#{text}", :boldyellow)
|
56
|
+
puts colorize_text('-' * text.length, :boldyellow)
|
57
|
+
puts "\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
def paragraphs(length, count = 3)
|
61
|
+
@sentence_generator.sentence_length = length
|
62
|
+
@sentence_generator.paragraph_length = count
|
63
|
+
|
64
|
+
header_2("Random Paragraph (#{@sentence_generator.paragraph_length} #{@sentence_generator.sentence_length} sentences)")
|
65
|
+
graf = @sentence_generator.paragraph
|
66
|
+
puts text(graf)
|
67
|
+
puts counter("#{graf.split(/ /).count} words, #{graf.length} characters")
|
68
|
+
end
|
69
|
+
|
70
|
+
def sentence(length)
|
71
|
+
header_2("Random #{length} sentence")
|
72
|
+
@sentence_generator.sentence_length = length
|
73
|
+
s = @sentence_generator.sentence
|
74
|
+
puts text(s)
|
75
|
+
puts counter("#{s.split(/ /).count} words, #{s.length} characters")
|
76
|
+
end
|
77
|
+
|
78
|
+
# Generate and print random combined sentences
|
79
|
+
def combined_sentences(length = nil)
|
80
|
+
number_of_sentences = length || 3
|
81
|
+
header_1('Random Combined Sentences:')
|
82
|
+
@sentence_generator.sentences(number_of_sentences).each_with_index do |_sentence, _index|
|
83
|
+
puts text(sentence(:medium))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def random_sentences
|
88
|
+
header_1('Random Sentences')
|
89
|
+
@sentence_generator.lengths.keys.each do |length|
|
90
|
+
sentence(length)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def random_paragraphs
|
95
|
+
header_1('Random Paragraphs')
|
96
|
+
@sentence_generator.lengths.keys.each do |length|
|
97
|
+
paragraphs(length, 3)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Generate and print specified number of words
|
102
|
+
def random_words
|
103
|
+
number_of_words = 10
|
104
|
+
header_1("#{number_of_words} Random Words")
|
105
|
+
s = @sentence_generator.words(number_of_words)
|
106
|
+
puts "#{marker} #{text(s)} "
|
107
|
+
puts counter("#{s.split(/ /).count} words, #{s.length} characters")
|
108
|
+
end
|
109
|
+
|
110
|
+
# Generate and print specified number of characters
|
111
|
+
def random_characters
|
112
|
+
header_1('Random Characters (exact length)')
|
113
|
+
[20, 50, 120, 200].each do |i|
|
114
|
+
chars = @sentence_generator.characters(i, whole_words: true)
|
115
|
+
puts "#{marker} #{colorize_text("#{i}:", :boldwhite)} #{text(chars)} #{counter(chars.length)}"
|
116
|
+
end
|
117
|
+
|
118
|
+
# Generate and print specified number of characters
|
119
|
+
max_characters = [15, 25, 53, 110, 600]
|
120
|
+
min_characters = [10, 20, 50, 100, 500]
|
121
|
+
header_1('Random Characters (length range)')
|
122
|
+
max_characters.count.times do |i|
|
123
|
+
chars = @sentence_generator.characters(min_characters[i], max_characters[i], whole_words: true)
|
124
|
+
range = "#{marker} #{colorize_text("[#{min_characters[i]}-#{max_characters[i]}]: ", :boldwhite)}"
|
125
|
+
puts "#{range}#{text(chars)} #{counter(chars.length)}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def marker
|
130
|
+
colorize_text('•', @colors[:marker])
|
131
|
+
end
|
132
|
+
|
133
|
+
def text(text)
|
134
|
+
colorize_text(text, @colors[:text])
|
135
|
+
end
|
136
|
+
|
137
|
+
def counter(length)
|
138
|
+
"#{colorize_text('[',
|
139
|
+
@colors[:bracket])}#{colorize_text("#{length}", @colors[:counter])}#{colorize_text(']', @colors[:bracket])}"
|
140
|
+
end
|
141
|
+
|
142
|
+
def print_test
|
143
|
+
combined_sentences(3)
|
144
|
+
random_sentences
|
145
|
+
random_paragraphs
|
146
|
+
random_words
|
147
|
+
random_characters
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
@options = {
|
153
|
+
source: :latin,
|
154
|
+
length: :medium,
|
155
|
+
paragraph_length: 3,
|
156
|
+
count: 1,
|
157
|
+
method: nil,
|
158
|
+
debug: false,
|
159
|
+
whitespace: true,
|
160
|
+
separator: ' '
|
161
|
+
}
|
162
|
+
|
163
|
+
OptionParser.new do |opts|
|
164
|
+
opts.banner = 'Usage: randw [options]'
|
165
|
+
|
166
|
+
opts.separator 'Options:'
|
167
|
+
|
168
|
+
opts.on('-S', '--source [SOURCE]', 'Specify the source language (default: latin)') do |source|
|
169
|
+
@options[:source] = case source
|
170
|
+
when /^e/
|
171
|
+
:english
|
172
|
+
when /^l/
|
173
|
+
:latin
|
174
|
+
when /^(co|pro)/
|
175
|
+
:corporate
|
176
|
+
when /^(me|ba|ca)/
|
177
|
+
:bacon
|
178
|
+
else
|
179
|
+
:latin
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
opts.on('-l', '--length [short|medium|long|very_long]', 'Specify the length of the sentence') do |length|
|
184
|
+
@options[:length] = case length
|
185
|
+
when /^s/
|
186
|
+
:short
|
187
|
+
when /^l/
|
188
|
+
:long
|
189
|
+
when /^v/
|
190
|
+
:very_long
|
191
|
+
else
|
192
|
+
:medium
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
opts.on('--graf-length [NUMBER]', 'Specify the number of sentences in a paragraph') do |length|
|
197
|
+
@options[:paragraph_length] = length.to_i
|
198
|
+
end
|
199
|
+
|
200
|
+
opts.on('-s', '--sentences [NUMBER]', 'Generate random sentences') do |number|
|
201
|
+
@options[:method] = :sentences
|
202
|
+
@options[:count] = number.to_i
|
203
|
+
end
|
204
|
+
|
205
|
+
opts.on('-p', '--paragraphs [NUMBER]', 'Generate random paragraphs') do |number|
|
206
|
+
@options[:method] = :paragraphs
|
207
|
+
@options[:count] = number
|
208
|
+
end
|
209
|
+
|
210
|
+
opts.on('-w', '--words [NUMBER]', 'Generate random words') do |number|
|
211
|
+
@options[:method] = :words
|
212
|
+
@options[:count] = number
|
213
|
+
end
|
214
|
+
|
215
|
+
opts.on('-c', '--characters [NUMBER]', 'Generate random characters') do |number|
|
216
|
+
@options[:method] = :characters
|
217
|
+
@options[:count] = number
|
218
|
+
end
|
219
|
+
|
220
|
+
opts.on('--password', 'Generate a random password') do
|
221
|
+
@options[:method] = :password
|
222
|
+
@options[:count] = 20
|
223
|
+
end
|
224
|
+
|
225
|
+
opts.on('--separator [CHAR]', 'Specify the separator character for the password') do |separator|
|
226
|
+
@options[:separator] = separator
|
227
|
+
end
|
228
|
+
|
229
|
+
opts.on('-n', '--no-whitespace', 'Specify whether to remove whitespace in generated text (characters only)') do
|
230
|
+
@options[:whitespace] = false
|
231
|
+
end
|
232
|
+
|
233
|
+
opts.on('-d', '--debug', 'Enable debug mode, displays sentence/word/character counts') do
|
234
|
+
@options[:debug] = true
|
235
|
+
end
|
236
|
+
|
237
|
+
opts.on('-h', '--help', 'Display this help message') do
|
238
|
+
puts opts
|
239
|
+
exit
|
240
|
+
end
|
241
|
+
|
242
|
+
opts.on('-v', '--version', 'Display the version') do
|
243
|
+
puts "RandomWords v#{RandomWords::VERSION}"
|
244
|
+
exit
|
245
|
+
end
|
246
|
+
|
247
|
+
opts.on('-t', '--test', 'Run the full debug test') do
|
248
|
+
@options[:method] = :test
|
249
|
+
@options[:debug] = true
|
250
|
+
end
|
251
|
+
end.parse!
|
252
|
+
|
253
|
+
def debug(msg)
|
254
|
+
return unless @options[:debug]
|
255
|
+
|
256
|
+
# length = msg.length
|
257
|
+
# message = RandomWords::Terminal.new.colorize_text(msg, :boldblack)
|
258
|
+
# puts RandomWords::Terminal.new.colorize_text('-' * length, :boldblack)
|
259
|
+
# puts message
|
260
|
+
# puts RandomWords::Terminal.new.colorize_text('-' * length, :boldblack)
|
261
|
+
warn RandomWords::Terminal.new.colorize_text(" [#{msg}]", :cyan)
|
262
|
+
end
|
263
|
+
|
264
|
+
@rw = RandomWords::Generator.new(@options[:source])
|
265
|
+
@rw.sentence_length = @options[:length] || :medium
|
266
|
+
@rw.paragraph_length = @options[:paragraph_length] || 3
|
267
|
+
@options[:count] = @options[:count].to_i
|
268
|
+
|
269
|
+
case @options[:method]
|
270
|
+
when :sentences
|
271
|
+
total = {
|
272
|
+
sentences: @options[:count],
|
273
|
+
words: 0,
|
274
|
+
characters: 0
|
275
|
+
}
|
276
|
+
@options[:count].times do
|
277
|
+
s = @rw.sentence
|
278
|
+
total[:words] += s.split(/ /).count
|
279
|
+
total[:characters] += s.length
|
280
|
+
print s
|
281
|
+
debug "#{s.split(/ /).count}w, #{s.length}c"
|
282
|
+
end
|
283
|
+
debug "Total: #{total[:sentences]}s, #{total[:words]}w, #{total[:characters]}c"
|
284
|
+
when :paragraphs
|
285
|
+
total = {
|
286
|
+
sentences: 0,
|
287
|
+
words: 0,
|
288
|
+
characters: 0
|
289
|
+
}
|
290
|
+
@options[:count].times do
|
291
|
+
p = @rw.paragraph
|
292
|
+
total[:sentences] += p.scan(/[?.!]/).count
|
293
|
+
total[:words] += p.split(/ /).count
|
294
|
+
total[:characters] += p.length
|
295
|
+
print p
|
296
|
+
debug "#{p.scan(/[?.!]/).count}s, #{p.split(/ /).count}w, #{p.length}c"
|
297
|
+
puts "\n\n"
|
298
|
+
end
|
299
|
+
debug "Total: #{total[:sentences]}s, #{total[:words]}w, #{total[:characters]}c"
|
300
|
+
when :words
|
301
|
+
w = @rw.words(@options[:count])
|
302
|
+
print w
|
303
|
+
debug "#{w.split(/ /).count}w, #{w.length}c"
|
304
|
+
when :characters
|
305
|
+
c = @rw.characters(@options[:count], whitespace: @options[:whitespace])
|
306
|
+
print c
|
307
|
+
debug "#{c.split(/ /).count}w, #{c.length}c"
|
308
|
+
when :password
|
309
|
+
p = @rw.characters(20, whitespace: @options[:whitespace])
|
310
|
+
|
311
|
+
m = p.match(/[oleat]/i)
|
312
|
+
if m
|
313
|
+
num_char = m.begin(0)
|
314
|
+
char = m[0].tr('oleat', '01347')
|
315
|
+
else
|
316
|
+
num_char = p.length
|
317
|
+
char = rand(10).to_s
|
318
|
+
end
|
319
|
+
p[num_char] = char
|
320
|
+
|
321
|
+
cap_char = rand(20)
|
322
|
+
cap_char = rand(20) while p[cap_char] == ' '
|
323
|
+
p[cap_char] = p[cap_char].upcase
|
324
|
+
|
325
|
+
tail_char = p =~ /[^a-z0-9]/i ? '' : %w[! @ # $ % ^ & * ( ) _ + - = ; : < > , . ? /].sample
|
326
|
+
|
327
|
+
print p.gsub(/ /, @options[:separator]) + tail_char
|
328
|
+
debug "#{p.split(@options[:separator]).count}w, #{p.length}c"
|
329
|
+
when :test
|
330
|
+
t = RandomWords::Terminal.new(@options[:source])
|
331
|
+
t.print_test
|
332
|
+
else
|
333
|
+
puts 'Please specify a valid method: sentences, paragraphs, words, or characters.'
|
334
|
+
end
|