random-words 1.0.5 → 1.0.7
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 +4 -4
- data/.rspec_status +166 -39
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +313 -0
- data/CHANGELOG.md +67 -0
- data/Gemfile +15 -12
- data/Gemfile.lock +46 -26
- data/README.md +208 -15
- data/bin/randw +258 -92
- data/lib/random-words/array.rb +71 -0
- data/lib/random-words/config.rb +254 -0
- data/lib/random-words/generator.rb +257 -94
- data/lib/random-words/hash.rb +16 -0
- data/lib/random-words/html2markdown.rb +205 -0
- data/lib/random-words/lorem-markdown.rb +397 -0
- data/lib/random-words/number-to-word.rb +139 -0
- data/lib/random-words/source.rb +106 -0
- data/lib/random-words/string.rb +224 -45
- data/lib/random-words/table-cleanup.rb +210 -0
- data/lib/random-words/version.rb +1 -1
- data/lib/random-words/words/1984/adjectives.txt +103 -0
- data/lib/random-words/words/1984/adverbs.txt +92 -0
- data/lib/random-words/words/1984/articles-plural.txt +10 -0
- data/lib/random-words/words/1984/articles-singular.txt +10 -0
- data/lib/random-words/words/1984/clauses.txt +79 -0
- data/lib/random-words/words/1984/config.yml +4 -0
- data/lib/random-words/words/1984/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/1984/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/1984/names.txt +12 -0
- data/lib/random-words/words/1984/nouns-plural.txt +89 -0
- data/lib/random-words/words/1984/nouns-singular.txt +74 -0
- data/lib/random-words/words/1984/numbers.yml +5 -0
- data/lib/random-words/words/1984/phrases.txt +16 -0
- data/lib/random-words/words/1984/prepositions.txt +89 -0
- data/lib/random-words/words/1984/terminators.txt +16 -0
- data/lib/random-words/words/1984/verbs-passive.txt +83 -0
- data/lib/random-words/words/1984/verbs-plural.txt +91 -0
- data/lib/random-words/words/1984/verbs-singular.txt +110 -0
- data/lib/random-words/words/alice/adjectives.txt +80 -0
- data/lib/random-words/words/alice/adverbs.txt +87 -0
- data/lib/random-words/words/alice/articles-plural.txt +10 -0
- data/lib/random-words/words/alice/articles-singular.txt +10 -0
- data/lib/random-words/words/alice/clauses.txt +81 -0
- data/lib/random-words/words/alice/config.yml +4 -0
- data/lib/random-words/words/alice/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/alice/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/alice/names.txt +10 -0
- data/lib/random-words/words/alice/nouns-plural.txt +95 -0
- data/lib/random-words/words/alice/nouns-singular.txt +82 -0
- data/lib/random-words/words/alice/numbers.yml +5 -0
- data/lib/random-words/words/alice/phrases.txt +16 -0
- data/lib/random-words/words/alice/prepositions.txt +45 -0
- data/lib/random-words/words/alice/terminators.txt +16 -0
- data/lib/random-words/words/alice/verbs-passive.txt +495 -0
- data/lib/random-words/words/alice/verbs-plural.txt +115 -0
- data/lib/random-words/words/alice/verbs-singular.txt +97 -0
- data/lib/random-words/words/bacon/clauses.txt +592 -592
- data/lib/random-words/words/bacon/config.yml +4 -0
- data/lib/random-words/words/bacon/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/bacon/names.txt +54 -0
- data/lib/random-words/words/bacon/numbers.yml +5 -0
- data/lib/random-words/words/bacon/phrases.txt +20 -0
- data/lib/random-words/words/bacon/prepositions.txt +45 -0
- data/lib/random-words/words/bacon/terminators.txt +16 -0
- data/lib/random-words/words/corporate/config.yml +4 -0
- data/lib/random-words/words/corporate/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/corporate/names.txt +74 -0
- data/lib/random-words/words/corporate/numbers.yml +5 -0
- data/lib/random-words/words/corporate/phrases.txt +29 -0
- data/lib/random-words/words/corporate/prepositions.txt +45 -0
- data/lib/random-words/words/corporate/terminators.txt +16 -0
- data/lib/random-words/words/doctor/adjectives.txt +92 -0
- data/lib/random-words/words/doctor/adverbs.txt +92 -0
- data/lib/random-words/words/doctor/articles-plural.txt +10 -0
- data/lib/random-words/words/doctor/articles-singular.txt +10 -0
- data/lib/random-words/words/doctor/clauses.txt +83 -0
- data/lib/random-words/words/doctor/config.yml +10 -0
- data/lib/random-words/words/doctor/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/doctor/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/doctor/names.txt +74 -0
- data/lib/random-words/words/doctor/nouns-plural.txt +84 -0
- data/lib/random-words/words/doctor/nouns-singular.txt +84 -0
- data/lib/random-words/words/doctor/numbers.yml +5 -0
- data/lib/random-words/words/doctor/phrases.txt +29 -0
- data/lib/random-words/words/doctor/prepositions.txt +45 -0
- data/lib/random-words/words/doctor/terminators.txt +16 -0
- data/lib/random-words/words/doctor/verbs-passive.txt +83 -0
- data/lib/random-words/words/doctor/verbs-plural.txt +88 -0
- data/lib/random-words/words/doctor/verbs-singular.txt +83 -0
- data/lib/random-words/words/english/clauses.txt +592 -592
- data/lib/random-words/words/english/config.yml +4 -0
- data/lib/random-words/words/english/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/english/names.txt +74 -0
- data/lib/random-words/words/english/numbers.yml +5 -0
- data/lib/random-words/words/english/phrases.txt +29 -0
- data/lib/random-words/words/english/prepositions.txt +45 -0
- data/lib/random-words/words/english/terminators.txt +16 -0
- data/lib/random-words/words/english/verbs-plural.txt +1 -0
- data/lib/random-words/words/english/verbs-singular.txt +1 -0
- data/lib/random-words/words/foulmouth/adjectives.txt +89 -0
- data/lib/random-words/words/foulmouth/adverbs.txt +97 -0
- data/lib/random-words/words/foulmouth/articles-plural.txt +12 -0
- data/lib/random-words/words/foulmouth/articles-singular.txt +11 -0
- data/lib/random-words/words/foulmouth/clauses.txt +74 -0
- data/lib/random-words/words/foulmouth/config.yml +4 -0
- data/lib/random-words/words/foulmouth/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/foulmouth/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/foulmouth/names.txt +81 -0
- data/lib/random-words/words/foulmouth/nouns-plural.txt +96 -0
- data/lib/random-words/words/foulmouth/nouns-singular.txt +99 -0
- data/lib/random-words/words/foulmouth/numbers.yml +5 -0
- data/lib/random-words/words/foulmouth/phrases.txt +30 -0
- data/lib/random-words/words/foulmouth/prepositions.txt +35 -0
- data/lib/random-words/words/foulmouth/terminators.txt +16 -0
- data/lib/random-words/words/foulmouth/verbs-passive.txt +143 -0
- data/lib/random-words/words/foulmouth/verbs-plural.txt +91 -0
- data/lib/random-words/words/foulmouth/verbs-singular.txt +104 -0
- data/lib/random-words/words/hipster/adjectives.txt +100 -0
- data/lib/random-words/words/hipster/adverbs.txt +89 -0
- data/lib/random-words/words/hipster/articles-plural.txt +10 -0
- data/lib/random-words/words/hipster/articles-singular.txt +10 -0
- data/lib/random-words/words/hipster/clauses.txt +180 -0
- data/lib/random-words/words/hipster/config.yml +4 -0
- data/lib/random-words/words/hipster/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/hipster/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/hipster/names.txt +73 -0
- data/lib/random-words/words/hipster/nouns-plural.txt +96 -0
- data/lib/random-words/words/hipster/nouns-singular.txt +100 -0
- data/lib/random-words/words/hipster/numbers.yml +5 -0
- data/lib/random-words/words/hipster/phrases.txt +21 -0
- data/lib/random-words/words/hipster/prepositions.txt +45 -0
- data/lib/random-words/words/hipster/terminators.txt +16 -0
- data/lib/random-words/words/hipster/verbs-passive.txt +88 -0
- data/lib/random-words/words/hipster/verbs-plural.txt +106 -0
- data/lib/random-words/words/hipster/verbs-singular.txt +114 -0
- data/lib/random-words/words/latin/config.yml +4 -0
- data/lib/random-words/words/latin/conjunctions-coordinating.txt +15 -0
- data/lib/random-words/words/latin/names.txt +93 -0
- data/lib/random-words/words/latin/numbers.yml +5 -0
- data/lib/random-words/words/latin/phrases.txt +16 -0
- data/lib/random-words/words/latin/prepositions.txt +18 -0
- data/lib/random-words/words/latin/terminators.txt +16 -0
- data/lib/random-words/words/spanish/adjectives.txt +81 -0
- data/lib/random-words/words/spanish/adverbs.txt +87 -0
- data/lib/random-words/words/spanish/articles-plural.txt +4 -0
- data/lib/random-words/words/spanish/articles-singular.txt +4 -0
- data/lib/random-words/words/spanish/clauses.txt +74 -0
- data/lib/random-words/words/spanish/config.yml +4 -0
- data/lib/random-words/words/spanish/conjunctions-coordinating.txt +8 -0
- data/lib/random-words/words/spanish/conjunctions-subordinate.txt +16 -0
- data/lib/random-words/words/spanish/names.txt +61 -0
- data/lib/random-words/words/spanish/nouns-plural.txt +92 -0
- data/lib/random-words/words/spanish/nouns-singular.txt +125 -0
- data/lib/random-words/words/spanish/numbers.yml +5 -0
- data/lib/random-words/words/spanish/phrases.txt +31 -0
- data/lib/random-words/words/spanish/prepositions.txt +31 -0
- data/lib/random-words/words/spanish/terminators.txt +17 -0
- data/lib/random-words/words/spanish/verbs-passive.txt +495 -0
- data/lib/random-words/words/spanish/verbs-plural.txt +326 -0
- data/lib/random-words/words/spanish/verbs-singular.txt +351 -0
- data/lib/random-words/words/veggie/adjectives.txt +111 -0
- data/lib/random-words/words/veggie/adverbs.txt +81 -0
- data/lib/random-words/words/veggie/articles-plural.txt +10 -0
- data/lib/random-words/words/veggie/articles-singular.txt +10 -0
- data/lib/random-words/words/veggie/clauses.txt +57 -0
- data/lib/random-words/words/veggie/config.yml +4 -0
- data/lib/random-words/words/veggie/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/veggie/conjunctions-subordinate.txt +29 -0
- data/lib/random-words/words/veggie/names.txt +93 -0
- data/lib/random-words/words/veggie/nouns-plural.txt +78 -0
- data/lib/random-words/words/veggie/nouns-singular.txt +105 -0
- data/lib/random-words/words/veggie/numbers.yml +5 -0
- data/lib/random-words/words/veggie/phrases.txt +20 -0
- data/lib/random-words/words/veggie/prepositions.txt +45 -0
- data/lib/random-words/words/veggie/terminators.txt +16 -0
- data/lib/random-words/words/veggie/verbs-passive.txt +56 -0
- data/lib/random-words/words/veggie/verbs-plural.txt +79 -0
- data/lib/random-words/words/veggie/verbs-singular.txt +79 -0
- data/lib/random-words.rb +28 -0
- data/random-words.gemspec +3 -1
- data/src/_README.md +208 -15
- metadata +181 -9
- data/lib/random-words/words/bacon/numbers.txt +0 -21
- data/lib/random-words/words/corporate/numbers.txt +0 -21
- data/lib/random-words/words/english/numbers.txt +0 -21
- data/lib/random-words/words/latin/numbers.txt +0 -21
data/bin/randw
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative
|
5
|
-
require
|
4
|
+
require_relative "../lib/random-words"
|
5
|
+
require "optparse"
|
6
6
|
|
7
7
|
module RandomWords
|
8
|
+
# Terminal methods for testing
|
8
9
|
class Terminal
|
9
10
|
def initialize(source = :english)
|
10
11
|
# Create an instance of the generator
|
11
12
|
@sentence_generator = RandomWords::Generator.new(source)
|
13
|
+
@sentence_generator.use_extended_punctuation = true
|
12
14
|
@colors = {
|
13
15
|
text: :yellow,
|
14
16
|
counter: :boldcyan,
|
15
17
|
marker: :boldgreen,
|
16
|
-
bracket: :cyan
|
18
|
+
bracket: :cyan,
|
19
|
+
language: :boldmagenta,
|
17
20
|
}
|
21
|
+
@sources = @sentence_generator.sources.keys.map(&:to_s)
|
18
22
|
end
|
19
23
|
|
20
24
|
def colors
|
@@ -27,15 +31,15 @@ module RandomWords
|
|
27
31
|
magenta: 35,
|
28
32
|
cyan: 36,
|
29
33
|
white: 37,
|
30
|
-
boldblack:
|
31
|
-
boldred:
|
32
|
-
boldgreen:
|
33
|
-
boldyellow:
|
34
|
-
boldblue:
|
35
|
-
boldmagenta:
|
36
|
-
boldcyan:
|
37
|
-
boldwhite:
|
38
|
-
reset: 0
|
34
|
+
boldblack: "1;30",
|
35
|
+
boldred: "1;31",
|
36
|
+
boldgreen: "1;32",
|
37
|
+
boldyellow: "1;33",
|
38
|
+
boldblue: "1;34",
|
39
|
+
boldmagenta: "1;35",
|
40
|
+
boldcyan: "1;36",
|
41
|
+
boldwhite: "1;37",
|
42
|
+
reset: 0,
|
39
43
|
}
|
40
44
|
end
|
41
45
|
|
@@ -47,19 +51,20 @@ module RandomWords
|
|
47
51
|
|
48
52
|
def header_1(text)
|
49
53
|
puts colorize_text("\n\n#{text}", :boldgreen)
|
50
|
-
puts colorize_text(
|
54
|
+
puts colorize_text("=" * text.length, :boldgreen)
|
51
55
|
puts "\n"
|
52
56
|
end
|
53
57
|
|
54
58
|
def header_2(text)
|
55
59
|
puts colorize_text("\n\n#{text}", :boldyellow)
|
56
|
-
puts colorize_text(
|
60
|
+
puts colorize_text("-" * text.length, :boldyellow)
|
57
61
|
puts "\n"
|
58
62
|
end
|
59
63
|
|
60
64
|
def paragraphs(length, count = 3)
|
61
65
|
@sentence_generator.sentence_length = length
|
62
66
|
@sentence_generator.paragraph_length = count
|
67
|
+
@sentence_generator.source = @sources.sample
|
63
68
|
|
64
69
|
header_2("Random Paragraph (#{@sentence_generator.paragraph_length} #{@sentence_generator.sentence_length} sentences)")
|
65
70
|
graf = @sentence_generator.paragraph
|
@@ -77,40 +82,60 @@ module RandomWords
|
|
77
82
|
|
78
83
|
# Generate and print random combined sentences
|
79
84
|
def combined_sentences(length = nil)
|
80
|
-
number_of_sentences = length ||
|
81
|
-
|
82
|
-
|
83
|
-
|
85
|
+
number_of_sentences = length || 2
|
86
|
+
|
87
|
+
header_1("Random Combined Sentences:")
|
88
|
+
@sources.count.times do |i|
|
89
|
+
@sentence_generator.source = @sources[i - 1]
|
90
|
+
@sentence_generator.sentence_length = :medium
|
91
|
+
@sentence_generator.paragraph_length = number_of_sentences
|
92
|
+
@sentence_generator.sentences(number_of_sentences)
|
93
|
+
s = @sentence_generator.sentence
|
94
|
+
puts "#{marker} #{text(s)}"
|
95
|
+
puts counter("#{s.split(/ /).count} words, #{s.length} characters")
|
96
|
+
puts colorize_text(" " * 2, :boldwhite)
|
84
97
|
end
|
85
98
|
end
|
86
99
|
|
87
100
|
def random_sentences
|
88
|
-
header_1(
|
89
|
-
@sentence_generator.lengths.keys.
|
101
|
+
header_1("Random Sentences")
|
102
|
+
@sentence_generator.lengths.keys.each_with_index do |length, index|
|
103
|
+
@sentence_generator.source = @sources[index]
|
90
104
|
sentence(length)
|
91
105
|
end
|
92
106
|
end
|
93
107
|
|
94
108
|
def random_paragraphs
|
95
|
-
header_1(
|
96
|
-
@sentence_generator.lengths.keys.
|
109
|
+
header_1("Random Paragraphs")
|
110
|
+
@sentence_generator.lengths.keys.each_with_index do |length, index|
|
111
|
+
@sentence_generator.source = @sources[index]
|
97
112
|
paragraphs(length, 3)
|
98
113
|
end
|
99
114
|
end
|
100
115
|
|
101
116
|
# Generate and print specified number of words
|
102
117
|
def random_words
|
103
|
-
number_of_words =
|
118
|
+
number_of_words = []
|
119
|
+
@sources.count.times do |i|
|
120
|
+
puts i
|
121
|
+
number_of_words << (i * i) * 5 + 10
|
122
|
+
end
|
123
|
+
|
104
124
|
header_1("#{number_of_words} Random Words")
|
105
|
-
|
106
|
-
|
107
|
-
|
125
|
+
@sources.each_with_index do |source, index|
|
126
|
+
header_2("#{number_of_words[index]} Random Words")
|
127
|
+
@sentence_generator.source = source
|
128
|
+
s = @sentence_generator.words(number_of_words[index])
|
129
|
+
puts "#{marker} #{text(s)} "
|
130
|
+
puts counter("#{s.split(/ /).count} words, #{s.length} characters")
|
131
|
+
end
|
108
132
|
end
|
109
133
|
|
110
134
|
# Generate and print specified number of characters
|
111
135
|
def random_characters
|
112
|
-
header_1(
|
113
|
-
[20, 50, 120, 200].
|
136
|
+
header_1("Random Characters (exact length)")
|
137
|
+
[20, 50, 120, 200, 500].each_with_index do |i, index|
|
138
|
+
@sentence_generator.source = @sources[index]
|
114
139
|
chars = @sentence_generator.characters(i, whole_words: true)
|
115
140
|
puts "#{marker} #{colorize_text("#{i}:", :boldwhite)} #{text(chars)} #{counter(chars.length)}"
|
116
141
|
end
|
@@ -118,8 +143,10 @@ module RandomWords
|
|
118
143
|
# Generate and print specified number of characters
|
119
144
|
max_characters = [15, 25, 53, 110, 600]
|
120
145
|
min_characters = [10, 20, 50, 100, 500]
|
121
|
-
|
146
|
+
|
147
|
+
header_1("Random Characters (length range)")
|
122
148
|
max_characters.count.times do |i|
|
149
|
+
@sentence_generator.source = @sources[i]
|
123
150
|
chars = @sentence_generator.characters(min_characters[i], max_characters[i], whole_words: true)
|
124
151
|
range = "#{marker} #{colorize_text("[#{min_characters[i]}-#{max_characters[i]}]: ", :boldwhite)}"
|
125
152
|
puts "#{range}#{text(chars)} #{counter(chars.length)}"
|
@@ -127,16 +154,22 @@ module RandomWords
|
|
127
154
|
end
|
128
155
|
|
129
156
|
def marker
|
130
|
-
colorize_text(
|
157
|
+
colorize_text("•", @colors[:marker])
|
131
158
|
end
|
132
159
|
|
133
160
|
def text(text)
|
134
161
|
colorize_text(text, @colors[:text])
|
135
162
|
end
|
136
163
|
|
164
|
+
def language
|
165
|
+
"#{colorize_text("(",
|
166
|
+
@colors[:bracket])}#{colorize_text("#{@sentence_generator.source}", @colors[:language])}#{colorize_text(")",
|
167
|
+
@colors[:bracket])}"
|
168
|
+
end
|
169
|
+
|
137
170
|
def counter(length)
|
138
|
-
"#{colorize_text(
|
139
|
-
@colors[:bracket])}#{colorize_text("#{length}", @colors[:counter])}#{colorize_text(
|
171
|
+
"#{colorize_text("[",
|
172
|
+
@colors[:bracket])}#{colorize_text("#{length}", @colors[:counter])}#{colorize_text("]", @colors[:bracket])} #{language}"
|
140
173
|
end
|
141
174
|
|
142
175
|
def print_test
|
@@ -149,6 +182,8 @@ module RandomWords
|
|
149
182
|
end
|
150
183
|
end
|
151
184
|
|
185
|
+
# Default options for the script
|
186
|
+
|
152
187
|
@options = {
|
153
188
|
source: :latin,
|
154
189
|
length: :medium,
|
@@ -157,94 +192,137 @@ end
|
|
157
192
|
method: nil,
|
158
193
|
debug: false,
|
159
194
|
whitespace: true,
|
160
|
-
separator:
|
195
|
+
separator: " ",
|
196
|
+
use_extended_punctuation: false,
|
161
197
|
}
|
162
198
|
|
199
|
+
markdown_help = <<HELP
|
200
|
+
dec: add em and strong
|
201
|
+
link: add links
|
202
|
+
ul: add unordered lists
|
203
|
+
ol: add ordered lists
|
204
|
+
dl: add definition lists
|
205
|
+
bq: add block quotes
|
206
|
+
code: add code spans and block
|
207
|
+
mark: add ==highlights==
|
208
|
+
headers: add headlines
|
209
|
+
image: add images
|
210
|
+
table: add tables
|
211
|
+
HELP
|
212
|
+
|
163
213
|
OptionParser.new do |opts|
|
164
|
-
opts.banner =
|
165
|
-
|
166
|
-
opts.separator
|
167
|
-
|
168
|
-
opts.on(
|
169
|
-
@options[: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
|
214
|
+
opts.banner = "Usage: randw [options]"
|
215
|
+
|
216
|
+
opts.separator "OPTIONS:"
|
217
|
+
|
218
|
+
opts.on("-S", "--source SOURCE", "Specify the source language (default: latin)") do |source|
|
219
|
+
@options[:source] = source.to_source
|
181
220
|
end
|
182
221
|
|
183
|
-
opts.on(
|
222
|
+
opts.on("-l", "--length LENGTH", "Specify the length of the sentence [short|medium|long|very_long]") do |length|
|
184
223
|
@options[:length] = case length
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
224
|
+
when /^s/
|
225
|
+
:short
|
226
|
+
when /^l/
|
227
|
+
:long
|
228
|
+
when /^v/
|
229
|
+
:very_long
|
230
|
+
else
|
231
|
+
:medium
|
232
|
+
end
|
194
233
|
end
|
195
234
|
|
196
|
-
opts.on(
|
235
|
+
opts.on("--graf-length NUMBER", "Specify the number of sentences in a paragraph") do |length|
|
197
236
|
@options[:paragraph_length] = length.to_i
|
198
237
|
end
|
199
238
|
|
200
|
-
opts.on(
|
239
|
+
opts.on("--[no-]extended", "Specify whether to use extended punctuation in generated text") do |value|
|
240
|
+
@options[:use_extended_punctuation] = value
|
241
|
+
end
|
242
|
+
|
243
|
+
opts.separator "GENERATORS:"
|
244
|
+
|
245
|
+
opts.on("-s", "--sentences [NUMBER]", "Generate NUMBER of random sentences (default: 3)") do |number|
|
201
246
|
@options[:method] = :sentences
|
202
|
-
@options[:count] = number
|
247
|
+
@options[:count] = number&.to_i || 3
|
203
248
|
end
|
204
249
|
|
205
|
-
opts.on(
|
250
|
+
opts.on("-p", "--paragraphs [NUMBER]", "Generate NUMBER of random paragraphs (default: 3)") do |number|
|
206
251
|
@options[:method] = :paragraphs
|
207
|
-
@options[:count] = number
|
252
|
+
@options[:count] = number&.to_i || 3
|
208
253
|
end
|
209
254
|
|
210
|
-
opts.on(
|
255
|
+
opts.on("-w", "--words [NUMBER]", "Generate NUMBER of random words (default: 10)") do |number|
|
211
256
|
@options[:method] = :words
|
212
|
-
@options[:count] = number
|
257
|
+
@options[:count] = number&.to_i || 10
|
213
258
|
end
|
214
259
|
|
215
|
-
opts.on(
|
260
|
+
opts.on("-c", "--characters [NUMBER]", "Generate random characters of length (default: 100)") do |number|
|
216
261
|
@options[:method] = :characters
|
217
|
-
@options[:count] = number
|
262
|
+
@options[:count] = number&.to_i || 100
|
218
263
|
end
|
219
264
|
|
220
|
-
opts.on(
|
265
|
+
opts.on("-m", "--markdown [SETTINGS]", "Generate random markdown text, comma separated string like \"latin,10,all\"\n#{markdown_help}") do |settings|
|
266
|
+
@options[:method] = :markdown
|
267
|
+
@options[:markdown_settings] = settings || "latin,10,all"
|
268
|
+
end
|
269
|
+
|
270
|
+
opts.on("-H", "--html [SETTINGS]", "Generate random html text, comma separated string like \"latin,10,all\"") do |settings|
|
271
|
+
@options[:method] = :html
|
272
|
+
@options[:markdown_settings] = settings || "latin,10,all"
|
273
|
+
end
|
274
|
+
|
275
|
+
opts.on("--password [LENGTH]", "Generate a random password of LENGTH (default: 20)") do |len|
|
221
276
|
@options[:method] = :password
|
222
|
-
@options[:count] = 20
|
277
|
+
@options[:count] = len&.to_i || 20
|
223
278
|
end
|
224
279
|
|
225
|
-
opts.
|
280
|
+
opts.separator "PASSWORD OPTIONS:"
|
281
|
+
|
282
|
+
opts.on("--separator CHAR", 'Specify the separator character for the password (default: " ")') do |separator|
|
226
283
|
@options[:separator] = separator
|
227
284
|
end
|
228
285
|
|
229
|
-
opts.on(
|
230
|
-
@options[:whitespace] =
|
286
|
+
opts.on("-n", "--[no-]whitespace", "Specify whether to remove whitespace in generated text (characters only)") do |value|
|
287
|
+
@options[:whitespace] = value
|
231
288
|
end
|
232
289
|
|
233
|
-
opts.
|
290
|
+
opts.separator "DICTIONARIES:"
|
291
|
+
|
292
|
+
opts.on("--list-dictionaries", "List available dictionaries") do
|
293
|
+
@rw = RandomWords::Generator.new(:latin)
|
294
|
+
|
295
|
+
@rw.sources.each do |k, v|
|
296
|
+
puts "#{v.name}: #{v.description}"
|
297
|
+
puts "triggers: (#{v.names.join(", ")})"
|
298
|
+
puts
|
299
|
+
end
|
300
|
+
Process.exit 0
|
301
|
+
end
|
302
|
+
|
303
|
+
opts.on("--create-dictionary [NAME]", "Create a new dictionary") do |name|
|
304
|
+
@rw = RandomWords::Generator.new(:latin)
|
305
|
+
@rw.create_dictionary(name)
|
306
|
+
Process.exit 0
|
307
|
+
end
|
308
|
+
|
309
|
+
opts.separator "OTHER OPTIONS:"
|
310
|
+
|
311
|
+
opts.on("-d", "--debug", "Enable debug mode, displays sentence/word/character counts") do
|
234
312
|
@options[:debug] = true
|
235
313
|
end
|
236
314
|
|
237
|
-
opts.on(
|
315
|
+
opts.on("-h", "--help", "Display this help message") do
|
238
316
|
puts opts
|
239
317
|
exit
|
240
318
|
end
|
241
319
|
|
242
|
-
opts.on(
|
320
|
+
opts.on("-v", "--version", "Display the version") do
|
243
321
|
puts "RandomWords v#{RandomWords::VERSION}"
|
244
322
|
exit
|
245
323
|
end
|
246
324
|
|
247
|
-
opts.on(
|
325
|
+
opts.on("-t", "--test", "Run the full debug test") do
|
248
326
|
@options[:method] = :test
|
249
327
|
@options[:debug] = true
|
250
328
|
end
|
@@ -261,9 +339,86 @@ def debug(msg)
|
|
261
339
|
warn RandomWords::Terminal.new.colorize_text(" [#{msg}]", :cyan)
|
262
340
|
end
|
263
341
|
|
342
|
+
def markdown_settings(settings)
|
343
|
+
base_config = RandomWords::Config.new(:latin).config
|
344
|
+
|
345
|
+
defaults = {
|
346
|
+
source: base_config[:source].is_a?(String) ? base_config[:source].to_source : base_config[:source],
|
347
|
+
grafs: 10,
|
348
|
+
sentences: base_config[:paragraph_length],
|
349
|
+
length: base_config[:sentence_length],
|
350
|
+
decorate: false,
|
351
|
+
link: false,
|
352
|
+
ul: false,
|
353
|
+
ol: false,
|
354
|
+
dl: false,
|
355
|
+
bq: false,
|
356
|
+
code: false,
|
357
|
+
mark: false,
|
358
|
+
headers: false,
|
359
|
+
table: false,
|
360
|
+
}
|
361
|
+
sources = []
|
362
|
+
RandomWords::Generator.new(:latin).sources.each { |k, v| sources.concat(v.names.map(&:to_s)) }
|
363
|
+
|
364
|
+
markdown_options = defaults.dup
|
365
|
+
settings = settings.split(%r{[,/.\|]}).map(&:strip)
|
366
|
+
|
367
|
+
settings.each do |setting|
|
368
|
+
case setting
|
369
|
+
when /^all$/
|
370
|
+
new_options = {
|
371
|
+
decorate: true,
|
372
|
+
link: true,
|
373
|
+
ul: true,
|
374
|
+
ol: true,
|
375
|
+
dl: true,
|
376
|
+
bq: true,
|
377
|
+
code: true,
|
378
|
+
mark: true,
|
379
|
+
headers: true,
|
380
|
+
image: true,
|
381
|
+
table: true,
|
382
|
+
}
|
383
|
+
markdown_options.merge!(new_options)
|
384
|
+
when Regexp.union(sources)
|
385
|
+
markdown_options[:source] = setting.to_source
|
386
|
+
when /^\d+$/
|
387
|
+
markdown_options[:grafs] = setting.to_i
|
388
|
+
when 'dec', 'decorate'
|
389
|
+
markdown_options[:decorate] = true
|
390
|
+
when 'link'
|
391
|
+
markdown_options[:link] = true
|
392
|
+
when 'ul'
|
393
|
+
markdown_options[:ul] = true
|
394
|
+
when 'ol'
|
395
|
+
markdown_options[:ol] = true
|
396
|
+
when 'dl'
|
397
|
+
markdown_options[:dl] = true
|
398
|
+
when 'bq', 'blockquote'
|
399
|
+
markdown_options[:bq] = true
|
400
|
+
when 'code'
|
401
|
+
markdown_options[:code] = true
|
402
|
+
when 'mark'
|
403
|
+
markdown_options[:mark] = true
|
404
|
+
when 'header', 'h'
|
405
|
+
markdown_options[:headers] = true
|
406
|
+
when 'table', 't'
|
407
|
+
markdown_options[:table] = true
|
408
|
+
when 'short', 's', 'medium', 'med', 'm', 'long', 'l', 'very_long', 'vl'
|
409
|
+
markdown_options[:length] = setting.to_length
|
410
|
+
else
|
411
|
+
markdown_options[:source] = setting.to_source
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
markdown_options
|
416
|
+
end
|
417
|
+
|
264
418
|
@rw = RandomWords::Generator.new(@options[:source])
|
265
419
|
@rw.sentence_length = @options[:length] || :medium
|
266
420
|
@rw.paragraph_length = @options[:paragraph_length] || 3
|
421
|
+
@rw.use_extended_punctuation = @options[:use_extended_punctuation] || false
|
267
422
|
@options[:count] = @options[:count].to_i
|
268
423
|
|
269
424
|
case @options[:method]
|
@@ -271,21 +426,21 @@ when :sentences
|
|
271
426
|
total = {
|
272
427
|
sentences: @options[:count],
|
273
428
|
words: 0,
|
274
|
-
characters: 0
|
429
|
+
characters: 0,
|
275
430
|
}
|
276
|
-
@options[:count].times do
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
end
|
431
|
+
# @options[:count].times do
|
432
|
+
s = @rw.sentences(@options[:count]).join(" ")
|
433
|
+
total[:words] += s.split(/ /).count
|
434
|
+
total[:characters] += s.length
|
435
|
+
print s
|
436
|
+
debug "#{s.split(/ /).count}w, #{s.length}c"
|
437
|
+
# end
|
283
438
|
debug "Total: #{total[:sentences]}s, #{total[:words]}w, #{total[:characters]}c"
|
284
439
|
when :paragraphs
|
285
440
|
total = {
|
286
441
|
sentences: 0,
|
287
442
|
words: 0,
|
288
|
-
characters: 0
|
443
|
+
characters: 0,
|
289
444
|
}
|
290
445
|
@options[:count].times do
|
291
446
|
p = @rw.paragraph
|
@@ -305,13 +460,24 @@ when :characters
|
|
305
460
|
c = @rw.characters(@options[:count], whitespace: @options[:whitespace])
|
306
461
|
print c
|
307
462
|
debug "#{c.split(/ /).count}w, #{c.length}c"
|
463
|
+
when :markdown, :html
|
464
|
+
settings = markdown_settings(@options[:markdown_settings])
|
465
|
+
@rw.source = settings[:source]
|
466
|
+
@rw.sentence_length = settings[:length] || :medium
|
467
|
+
@rw.paragraph_length = settings[:sentences] || 5
|
468
|
+
@rw.use_extended_punctuation = settings[:use_extended_punctuation] || false
|
469
|
+
if @options[:method] == :markdown
|
470
|
+
puts @rw.markdown(settings)
|
471
|
+
else
|
472
|
+
puts @rw.html(settings)
|
473
|
+
end
|
308
474
|
when :password
|
309
475
|
p = @rw.characters(20, whitespace: @options[:whitespace])
|
310
476
|
|
311
|
-
m = p.match(/[
|
477
|
+
m = p.match(/[oleats]/i)
|
312
478
|
if m
|
313
479
|
num_char = m.begin(0)
|
314
|
-
char = m[0].tr(
|
480
|
+
char = m[0].tr("oleats", "013475")
|
315
481
|
else
|
316
482
|
num_char = p.length
|
317
483
|
char = rand(10).to_s
|
@@ -319,10 +485,10 @@ when :password
|
|
319
485
|
p[num_char] = char
|
320
486
|
|
321
487
|
cap_char = rand(20)
|
322
|
-
cap_char = rand(20) while p[cap_char]
|
488
|
+
cap_char = rand(20) while p[cap_char] !~ /[a-z]/
|
323
489
|
p[cap_char] = p[cap_char].upcase
|
324
490
|
|
325
|
-
tail_char = p =~ /[^a-z0-9]/i ?
|
491
|
+
tail_char = p =~ /[^a-z0-9]/i ? "" : %w[! @ # $ % ^ & * ( ) _ + - = ; : < > , . ? /].sample
|
326
492
|
|
327
493
|
print p.gsub(/ /, @options[:separator]) + tail_char
|
328
494
|
debug "#{p.split(@options[:separator]).count}w, #{p.length}c"
|
@@ -330,5 +496,5 @@ when :test
|
|
330
496
|
t = RandomWords::Terminal.new(@options[:source])
|
331
497
|
t.print_test
|
332
498
|
else
|
333
|
-
puts
|
499
|
+
puts "Please specify a valid method: sentences, paragraphs, words, or characters."
|
334
500
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RandomWords
|
4
|
+
# Array helpers for RandomWords
|
5
|
+
# This module extends the Array class with additional methods for manipulating arrays.
|
6
|
+
class ::Array
|
7
|
+
# Split a terminators array into terminators and
|
8
|
+
# extended punctuation based on a line without a comma
|
9
|
+
# @return [Array<Array<String>>]
|
10
|
+
# An array containing two arrays: the first for terminators
|
11
|
+
# and the second for extended punctuation
|
12
|
+
def split_terminators
|
13
|
+
terminators = []
|
14
|
+
extended_punctuation = []
|
15
|
+
terminators_ended = false
|
16
|
+
each do |line|
|
17
|
+
if line.include?(',') && !terminators_ended
|
18
|
+
terminators << line.split(',').map(&:strip)
|
19
|
+
elsif terminators_ended
|
20
|
+
extended_punctuation << line.split(',').map(&:strip)
|
21
|
+
else
|
22
|
+
terminators_ended = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
terminators.delete_if { |line| line[1].empty? }
|
26
|
+
extended_punctuation.delete_if { |line| line[1].empty? }
|
27
|
+
[terminators, extended_punctuation]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Split a names list into first and last names
|
31
|
+
# Splits the names at blank line into two arrays: first names and last names.
|
32
|
+
# @return [Array<Array<String>, Array<String>>]
|
33
|
+
def split_names
|
34
|
+
first_names = []
|
35
|
+
last_names = []
|
36
|
+
full_names = []
|
37
|
+
first_names_ended = false
|
38
|
+
last_names_ended = false
|
39
|
+
|
40
|
+
sections = [[]]
|
41
|
+
idx = 0
|
42
|
+
each do |line|
|
43
|
+
if line.strip.empty? || line !~ /^[[:word:]]/i
|
44
|
+
idx += 1
|
45
|
+
sections[idx] = []
|
46
|
+
else
|
47
|
+
sections[idx] << line.strip
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if sections.length == 1
|
52
|
+
first_names = []
|
53
|
+
last_names = []
|
54
|
+
full_names = sections[0]
|
55
|
+
elsif sections.length == 2
|
56
|
+
first_names = sections[0]
|
57
|
+
last_names = sections[1]
|
58
|
+
full_names = []
|
59
|
+
else
|
60
|
+
first_names = sections[0]
|
61
|
+
last_names = sections[1]
|
62
|
+
full_names = sections[2]
|
63
|
+
end
|
64
|
+
|
65
|
+
first_names.delete_if(&:empty?)
|
66
|
+
last_names.delete_if(&:empty?)
|
67
|
+
full_names.delete_if(&:empty?)
|
68
|
+
[first_names, last_names, full_names]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|