random-words 1.0.12 → 1.0.13
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/.rubocop.yml +18 -86
- data/CHANGELOG.md +16 -0
- data/bin/randw +23 -9
- data/generator.cgi +155 -0
- data/lib/random-words/array.rb +0 -2
- data/lib/random-words/boolean.rb +1 -1
- data/lib/random-words/config.rb +6 -6
- data/lib/random-words/generator.rb +25 -27
- data/lib/random-words/html2markdown.rb +5 -5
- data/lib/random-words/{lorem-html.rb → lorem_html.rb} +89 -59
- data/lib/random-words/{number-to-word.rb → number_to_word.rb} +5 -5
- data/lib/random-words/numeric.rb +2 -2
- data/lib/random-words/string.rb +10 -3
- data/lib/random-words/terminal.rb +15 -13
- data/lib/random-words/version.rb +1 -1
- data/lib/random-words/words/walken/adjectives.txt +139 -0
- data/lib/random-words/words/walken/adverbs.txt +164 -0
- data/lib/random-words/words/walken/articles-plural.txt +10 -0
- data/lib/random-words/words/walken/articles-singular.txt +10 -0
- data/lib/random-words/words/walken/clauses.txt +200 -0
- data/lib/random-words/words/walken/config.yml +4 -0
- data/lib/random-words/words/walken/conjunctions-coordinating.txt +20 -0
- data/lib/random-words/words/walken/conjunctions-subordinate.txt +28 -0
- data/lib/random-words/words/walken/names.txt +101 -0
- data/lib/random-words/words/walken/nouns-plural.txt +330 -0
- data/lib/random-words/words/walken/nouns-singular.txt +500 -0
- data/lib/random-words/words/walken/numbers.yml +5 -0
- data/lib/random-words/words/walken/phrases.txt +45 -0
- data/lib/random-words/words/walken/prepositions.txt +45 -0
- data/lib/random-words/words/walken/terminators.txt +17 -0
- data/lib/random-words/words/walken/verbs-passive.txt +370 -0
- data/lib/random-words/words/walken/verbs-plural.txt +294 -0
- data/lib/random-words/words/walken/verbs-singular.txt +262 -0
- data/lib/random-words.rb +2 -2
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31da4c2eaac6cfdd53576f5453621759a9f17d36dc68abca44d4d70abeb281f8
|
4
|
+
data.tar.gz: 436e1f6aa43654687fb2eb2a7920446ee1ab0815bb1d8d6508cd25e423e9998a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f643e4685954135a314fe45835320b316fd68a04edc4d41dd4a6bc5cd13041f1cd79816e3453ab83db048f295bba5dfa514a67e7cd5b1bd088374149804ac08a
|
7
|
+
data.tar.gz: b934b0cf6d354b513e8c7d58d7b272576054c8ac256fd704711f28a9f2bceed1951a50971e4ab0604fafb5710dc96fffb39465ce7f971b7b0b45b0081edfeefc
|
data/.rubocop.yml
CHANGED
@@ -2,6 +2,7 @@ inherit_from: .rubocop_todo.yml
|
|
2
2
|
|
3
3
|
AllCops:
|
4
4
|
NewCops: enable
|
5
|
+
SuggestExtensions: false
|
5
6
|
|
6
7
|
# Offense count: 3
|
7
8
|
# This cop supports safe autocorrection (--autocorrect).
|
@@ -21,35 +22,27 @@ Lint/UselessAssignment:
|
|
21
22
|
# Offense count: 3
|
22
23
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
23
24
|
Metrics/AbcSize:
|
24
|
-
Max:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Metrics/ClassLength:
|
29
|
-
Max: 350
|
25
|
+
Max: 60
|
26
|
+
Exclude:
|
27
|
+
- 'lib/random-words/lorem_html.rb'
|
28
|
+
- 'lib/random-words/html2markdown.rb'
|
30
29
|
|
31
30
|
# Offense count: 2
|
32
31
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
33
32
|
Metrics/CyclomaticComplexity:
|
34
|
-
Max:
|
35
|
-
|
36
|
-
|
37
|
-
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
38
|
-
Metrics/MethodLength:
|
39
|
-
Max: 50
|
33
|
+
Max: 20
|
34
|
+
Exclude:
|
35
|
+
- 'lib/random-words/html2markdown.rb'
|
40
36
|
|
41
37
|
# Offense count: 1
|
42
38
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
43
39
|
Metrics/PerceivedComplexity:
|
44
|
-
Max:
|
45
|
-
|
46
|
-
# Offense count: 1
|
47
|
-
# Configuration parameters: AllowedConstants.
|
48
|
-
Style/Documentation:
|
40
|
+
Max: 20
|
49
41
|
Exclude:
|
50
|
-
- '
|
51
|
-
|
52
|
-
|
42
|
+
- 'lib/random-words/html2markdown.rb'
|
43
|
+
|
44
|
+
Metrics/ParameterLists:
|
45
|
+
Max: 10
|
53
46
|
|
54
47
|
# Offense count: 1
|
55
48
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
@@ -63,18 +56,14 @@ Style/SpecialGlobalVars:
|
|
63
56
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
64
57
|
# URISchemes: http, https
|
65
58
|
Layout/LineLength:
|
66
|
-
Max:
|
59
|
+
Max: 150
|
67
60
|
Exclude:
|
68
61
|
- bin/randw
|
69
62
|
|
70
63
|
Metrics/MethodLength:
|
71
|
-
Max:
|
64
|
+
Max: 100
|
72
65
|
Exclude:
|
73
|
-
- lib/random-words/
|
74
|
-
- lib/random-words/lorem-markdown.rb
|
75
|
-
- lib/random-words/string.rb
|
76
|
-
- lib/random-words/table-cleanup.rb
|
77
|
-
- lib/random-words/html2markdown.rb
|
66
|
+
- 'lib/random-words/html2markdown.rb'
|
78
67
|
|
79
68
|
# Offense count: 1
|
80
69
|
# This cop supports safe autocorrection (--autocorrect).
|
@@ -100,16 +89,6 @@ Layout/EndAlignment:
|
|
100
89
|
Exclude:
|
101
90
|
- 'bin/randw'
|
102
91
|
|
103
|
-
# Offense count: 2
|
104
|
-
# This cop supports safe autocorrection (--autocorrect).
|
105
|
-
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
106
|
-
# URISchemes: http, https
|
107
|
-
Layout/LineLength:
|
108
|
-
Exclude:
|
109
|
-
- 'bin/randw'
|
110
|
-
- 'lib/random-words/generator.rb'
|
111
|
-
- 'random-words.gemspec'
|
112
|
-
|
113
92
|
# Offense count: 1
|
114
93
|
# This cop supports safe autocorrection (--autocorrect).
|
115
94
|
Lint/AmbiguousOperatorPrecedence:
|
@@ -149,63 +128,16 @@ Lint/UselessConstantScoping:
|
|
149
128
|
Exclude:
|
150
129
|
- 'lib/random-words/generator.rb'
|
151
130
|
|
152
|
-
# Offense count: 12
|
153
|
-
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
154
|
-
Metrics/AbcSize:
|
155
|
-
Exclude:
|
156
|
-
- 'bin/randw'
|
157
|
-
- 'lib/random-words/config.rb'
|
158
|
-
- 'lib/random-words/generator.rb'
|
159
|
-
- 'lib/random-words/html2markdown.rb'
|
160
|
-
- 'lib/random-words/lorem-markdown.rb'
|
161
|
-
- 'lib/random-words/source.rb'
|
162
|
-
- 'lib/random-words/table-cleanup.rb'
|
163
|
-
|
164
131
|
# Offense count: 19
|
165
132
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
166
133
|
# AllowedMethods: refine
|
167
134
|
Metrics/BlockLength:
|
168
|
-
Max:
|
135
|
+
Max: 300
|
169
136
|
|
170
137
|
# Offense count: 1
|
171
138
|
# Configuration parameters: CountComments, Max, CountAsOne.
|
172
139
|
Metrics/ClassLength:
|
173
|
-
|
174
|
-
- 'lib/random-words/generator.rb'
|
175
|
-
|
176
|
-
# Offense count: 9
|
177
|
-
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
178
|
-
Metrics/CyclomaticComplexity:
|
179
|
-
Exclude:
|
180
|
-
- 'bin/randw'
|
181
|
-
- 'lib/random-words/array.rb'
|
182
|
-
- 'lib/random-words/config.rb'
|
183
|
-
- 'lib/random-words/generator.rb'
|
184
|
-
- 'lib/random-words/html2markdown.rb'
|
185
|
-
- 'lib/random-words/lorem-markdown.rb'
|
186
|
-
- 'lib/random-words/table-cleanup.rb'
|
187
|
-
|
188
|
-
# Offense count: 2
|
189
|
-
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
|
190
|
-
Metrics/MethodLength:
|
191
|
-
Exclude:
|
192
|
-
- 'bin/randw'
|
193
|
-
- 'lib/random-words/html2markdown.rb'
|
194
|
-
|
195
|
-
# Offense count: 1
|
196
|
-
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
197
|
-
Metrics/ParameterLists:
|
198
|
-
Max: 7
|
199
|
-
|
200
|
-
# Offense count: 7
|
201
|
-
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
202
|
-
Metrics/PerceivedComplexity:
|
203
|
-
Exclude:
|
204
|
-
- 'lib/random-words/array.rb'
|
205
|
-
- 'lib/random-words/generator.rb'
|
206
|
-
- 'lib/random-words/html2markdown.rb'
|
207
|
-
- 'lib/random-words/lorem-markdown.rb'
|
208
|
-
- 'lib/random-words/table-cleanup.rb'
|
140
|
+
Max: 500
|
209
141
|
|
210
142
|
# Offense count: 3
|
211
143
|
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
data/CHANGELOG.md
CHANGED
data/bin/randw
CHANGED
@@ -155,7 +155,7 @@ OptionParser.new do |opts|
|
|
155
155
|
end.parse!
|
156
156
|
|
157
157
|
def debug(msg)
|
158
|
-
return unless @options[:debug]
|
158
|
+
return unless @options[:debug] && @options[:debug_level]&.positive?
|
159
159
|
|
160
160
|
# length = msg.length
|
161
161
|
# message = RandomWords::Terminal.new.colorize_text(msg, :boldblack)
|
@@ -331,23 +331,36 @@ when :markdown, :html
|
|
331
331
|
puts @rw.html(settings)
|
332
332
|
end
|
333
333
|
when :password
|
334
|
-
p = @rw.characters(20, whitespace: @options[:whitespace])
|
334
|
+
p = @rw.characters(20, whitespace: @options[:whitespace], article: false)
|
335
335
|
|
336
|
-
m = p.match(/[
|
336
|
+
m = p.match(/[olzeasbtg]/i)
|
337
337
|
if m
|
338
338
|
num_char = m.begin(0)
|
339
|
-
char = m[0].tr("
|
339
|
+
char = m[0].tr("olzeasbtbg", "0123456789")
|
340
340
|
else
|
341
341
|
num_char = p.length
|
342
|
-
char = rand(
|
342
|
+
char = rand(9).to_s
|
343
343
|
end
|
344
344
|
p[num_char] = char
|
345
345
|
|
346
|
-
|
347
|
-
|
346
|
+
m = p.match(/[hcigatsbp]/i)
|
347
|
+
if m
|
348
|
+
sp_char = m.begin(0)
|
349
|
+
char = m[0].tr("hcigatsbp", "#<!&@+$>?")
|
350
|
+
end
|
351
|
+
p[sp_char] = char
|
352
|
+
|
353
|
+
cap_char = rand(19)
|
354
|
+
cap_char = rand(19) while p[cap_char] !~ /[a-z]/
|
348
355
|
p[cap_char] = p[cap_char].upcase
|
349
356
|
|
350
|
-
|
357
|
+
special = %w[! @ # $ % ^ & * ( ) _ + - = ; : < > , . ? /]
|
358
|
+
|
359
|
+
tail_char = if special.include?(@options[:separator]) || p =~ /#{Regexp.union(special)}/
|
360
|
+
''
|
361
|
+
else
|
362
|
+
/[^a-z0-9 ]/i.match?(p) ? "" : special.sample
|
363
|
+
end
|
351
364
|
|
352
365
|
print p.gsub(/ /, @options[:separator]) + tail_char
|
353
366
|
debug "#{p.split(@options[:separator]).count}w, #{p.length}c"
|
@@ -355,5 +368,6 @@ when :test
|
|
355
368
|
t = RandomWords::Terminal.new(@options[:source])
|
356
369
|
t.print_test
|
357
370
|
else
|
358
|
-
puts "Please specify a valid method:
|
371
|
+
puts "Please specify a valid method: "
|
372
|
+
puts "sentences, paragraphs, words, characters, password, markdown, html"
|
359
373
|
end
|
data/generator.cgi
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'cgi'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'random-words'
|
9
|
+
|
10
|
+
# Main script execution
|
11
|
+
|
12
|
+
if __FILE__ == $PROGRAM_NAME
|
13
|
+
def param?(param)
|
14
|
+
# Returns true if the parameter is present.
|
15
|
+
@params.key?(param) && @params[param][0].trueish?
|
16
|
+
end
|
17
|
+
|
18
|
+
def markdown_settings(settings)
|
19
|
+
base_config = RandomWords::Config.new(:latin).config
|
20
|
+
|
21
|
+
defaults = {
|
22
|
+
source: base_config[:source].is_a?(String) ? base_config[:source].to_source : base_config[:source],
|
23
|
+
grafs: 10,
|
24
|
+
sentences: base_config[:paragraph_length],
|
25
|
+
length: base_config[:sentence_length],
|
26
|
+
decorate: false,
|
27
|
+
link: false,
|
28
|
+
ul: false,
|
29
|
+
ol: false,
|
30
|
+
dl: false,
|
31
|
+
bq: false,
|
32
|
+
code: false,
|
33
|
+
mark: false,
|
34
|
+
headers: false,
|
35
|
+
table: false,
|
36
|
+
extended: false,
|
37
|
+
footnote: false,
|
38
|
+
hr: false,
|
39
|
+
meta_type: nil,
|
40
|
+
complete: false,
|
41
|
+
style: 'style.css'
|
42
|
+
}
|
43
|
+
sources = []
|
44
|
+
RandomWords::Generator.new(:latin).sources.each { |k, v| sources.concat(v.names.map(&:to_s)) }
|
45
|
+
|
46
|
+
markdown_options = defaults.dup
|
47
|
+
settings = settings.split(%r{[,/\|]}).map(&:strip)
|
48
|
+
|
49
|
+
settings.each do |setting|
|
50
|
+
case setting
|
51
|
+
when /^all$/
|
52
|
+
new_options = {
|
53
|
+
decorate: true,
|
54
|
+
link: true,
|
55
|
+
ul: true,
|
56
|
+
ol: true,
|
57
|
+
dl: true,
|
58
|
+
bq: true,
|
59
|
+
code: true,
|
60
|
+
mark: true,
|
61
|
+
headers: true,
|
62
|
+
image: true,
|
63
|
+
table: true,
|
64
|
+
extended: true,
|
65
|
+
footnote: true,
|
66
|
+
hr: true
|
67
|
+
}
|
68
|
+
markdown_options.merge!(new_options)
|
69
|
+
when Regexp.union(sources)
|
70
|
+
markdown_options[:source] = setting.to_source
|
71
|
+
when /^\d+$/
|
72
|
+
markdown_options[:grafs] = setting.to_i
|
73
|
+
when 'dec', 'decorate'
|
74
|
+
markdown_options[:decorate] = true
|
75
|
+
when 'link'
|
76
|
+
markdown_options[:link] = true
|
77
|
+
when 'ul'
|
78
|
+
markdown_options[:ul] = true
|
79
|
+
when 'ol'
|
80
|
+
markdown_options[:ol] = true
|
81
|
+
when 'dl'
|
82
|
+
markdown_options[:dl] = true
|
83
|
+
when 'bq', 'blockquote'
|
84
|
+
markdown_options[:bq] = true
|
85
|
+
when 'code'
|
86
|
+
markdown_options[:code] = true
|
87
|
+
when 'mark'
|
88
|
+
markdown_options[:mark] = true
|
89
|
+
when 'header', 'h'
|
90
|
+
markdown_options[:headers] = true
|
91
|
+
when 'table', 't'
|
92
|
+
markdown_options[:table] = true
|
93
|
+
when 'short', 's', 'medium', 'med', 'm', 'long', 'l', 'very_long', 'vl'
|
94
|
+
markdown_options[:length] = setting.to_length
|
95
|
+
when 'x', 'extended'
|
96
|
+
markdown_options[:extended] = true
|
97
|
+
when 'fn', 'footnotes'
|
98
|
+
markdown_options[:footnote] = true
|
99
|
+
when 'img', 'image'
|
100
|
+
markdown_options[:image] = true
|
101
|
+
when 'hr'
|
102
|
+
markdown_options[:hr] = true
|
103
|
+
when 'comp', 'complete'
|
104
|
+
markdown_options[:complete] = true
|
105
|
+
when /^(style|css):(.*)$/i
|
106
|
+
markdown_options[:style] = Regexp.last_match(2)
|
107
|
+
when /^meta:(.*?)$/i
|
108
|
+
case Regexp.last_match(1)
|
109
|
+
when 'mmd', 'multimarkdown'
|
110
|
+
markdown_options[:meta_type] = :multimarkdown
|
111
|
+
when 'yaml'
|
112
|
+
markdown_options[:meta_type] = :yaml
|
113
|
+
end
|
114
|
+
else
|
115
|
+
markdown_options[:source] = setting.to_source
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
markdown_options
|
120
|
+
end
|
121
|
+
|
122
|
+
cgi = CGI.new
|
123
|
+
args = ENV.fetch('REQUEST_URI', nil)
|
124
|
+
args = args.sub(%r{^/md-lipsum/api/4}, '') unless args.nil?
|
125
|
+
args = 'all' if args.nil?
|
126
|
+
|
127
|
+
settings = markdown_settings(args)
|
128
|
+
@rw.source = settings[:source]
|
129
|
+
@rw.sentence_length = settings[:length] || :medium
|
130
|
+
@rw.paragraph_length = settings[:sentences] || 5
|
131
|
+
|
132
|
+
@rw.use_extended_punctuation = settings[:extended] ? true : false
|
133
|
+
settings[:extended] = @rw.use_extended_punctuation
|
134
|
+
|
135
|
+
@params = cgi.params
|
136
|
+
settings[:complete] = true if param?('complete')
|
137
|
+
settings[:style] = @params['style'][0] if @params.key?('style')
|
138
|
+
# credit = "\n\n<!-- Generated by [md-lipsum](https://brettterpstra.com/md-lipsum/) -->\n"
|
139
|
+
|
140
|
+
settings[:source] = @params['source'][0].to_source if @params.key?('source')
|
141
|
+
|
142
|
+
if param?('html') || param?('preview') || param?('complete')
|
143
|
+
if param?('preview')
|
144
|
+
print cgi.header('type' => 'text/html', 'expires' => Time.now - 180)
|
145
|
+
puts @rw.html(settings)
|
146
|
+
else
|
147
|
+
print cgi.header('type' => 'text/plain', 'expires' => Time.now - 180)
|
148
|
+
puts @rw.html(settings)
|
149
|
+
end
|
150
|
+
else
|
151
|
+
print cgi.header('type' => 'text/plain', 'expires' => Time.now - 180)
|
152
|
+
|
153
|
+
puts @rw.markdown(settings)
|
154
|
+
end
|
155
|
+
end
|
data/lib/random-words/array.rb
CHANGED
data/lib/random-words/boolean.rb
CHANGED
data/lib/random-words/config.rb
CHANGED
@@ -34,9 +34,6 @@ module RandomWords
|
|
34
34
|
# Source directory for languages
|
35
35
|
attr_reader :source_dir
|
36
36
|
|
37
|
-
# Base config
|
38
|
-
attr_reader :config
|
39
|
-
|
40
37
|
# Initialize the config with the given language
|
41
38
|
# @param lang [Symbol] The language to use
|
42
39
|
# @raise [RuntimeError] if no dictionary is found for the given language
|
@@ -117,7 +114,9 @@ module RandomWords
|
|
117
114
|
# @return [Symbol, nil] The language symbol if successful, nil otherwise
|
118
115
|
def create_user_dictionary(lang = nil)
|
119
116
|
return lang.to_sym if File.directory?(File.join(config_dir, 'words',
|
120
|
-
lang)) && all_parts_of_speech?(
|
117
|
+
lang)) && all_parts_of_speech?(
|
118
|
+
File.join(config_dir, 'words', lang), lang
|
119
|
+
)
|
121
120
|
|
122
121
|
lang_dir = File.join(config_dir, 'words', lang)
|
123
122
|
|
@@ -153,7 +152,8 @@ module RandomWords
|
|
153
152
|
warn "Created #{target_file}"
|
154
153
|
end
|
155
154
|
|
156
|
-
unless all_parts_of_speech?(lang_dir,
|
155
|
+
unless all_parts_of_speech?(lang_dir,
|
156
|
+
lang) || (RandomWords.testing && !RandomWords.tested.include?('create_user_dictionary'))
|
157
157
|
return
|
158
158
|
end
|
159
159
|
|
@@ -212,7 +212,7 @@ module RandomWords
|
|
212
212
|
source: configuration[:source].to_source || :latin,
|
213
213
|
sentence_length: configuration[:length].to_length || :medium,
|
214
214
|
paragraph_length: configuration[:paragraph_length].to_i || 5,
|
215
|
-
use_extended_punctuation:
|
215
|
+
use_extended_punctuation: ext_punc&.trueish? || false
|
216
216
|
}
|
217
217
|
end
|
218
218
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# !/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Random Sentence Generator
|
@@ -92,7 +92,7 @@ module RandomWords
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# Display debug message
|
95
|
-
def
|
95
|
+
def dbg(msg)
|
96
96
|
return unless @debug
|
97
97
|
|
98
98
|
"%#{msg}%"
|
@@ -241,7 +241,7 @@ module RandomWords
|
|
241
241
|
result = SENTENCE_PARTS.cycle.take(number).map { |part| send(part.to_sym) }.take(number)
|
242
242
|
result.map do |word|
|
243
243
|
word.split(/ /).last
|
244
|
-
end.join(' ').compress
|
244
|
+
end.join(' ').article_agree.compress
|
245
245
|
end
|
246
246
|
|
247
247
|
# Generate a series of random words up to a specified length
|
@@ -254,7 +254,7 @@ module RandomWords
|
|
254
254
|
# characters(50) # Generates a string with at least 50 characters
|
255
255
|
# characters(50, 100) # Generates a string with between 50 and 100 characters
|
256
256
|
# characters(50, whole_words: false) # Generates a string with 50 characters allowing word truncation
|
257
|
-
def characters(min, max = nil, whole_words: true, whitespace: true, dead_switch: 0)
|
257
|
+
def characters(min, max = nil, whole_words: true, whitespace: true, article: true, dead_switch: 0)
|
258
258
|
result = ''
|
259
259
|
max ||= min
|
260
260
|
raise ArgumentError, 'Infinite loop detected' if dead_switch > 40
|
@@ -262,7 +262,7 @@ module RandomWords
|
|
262
262
|
whole_words = false if dead_switch > 15
|
263
263
|
|
264
264
|
space = whitespace ? ' ' : ''
|
265
|
-
current_part = 0
|
265
|
+
current_part = article ? 0 : 1
|
266
266
|
while result.length < max && result.length < min
|
267
267
|
word = send(SENTENCE_PARTS[current_part].to_sym)
|
268
268
|
word.gsub!(/ +/, '') unless whitespace
|
@@ -342,7 +342,6 @@ module RandomWords
|
|
342
342
|
code_langs[Random.rand(code_langs.count)]
|
343
343
|
end
|
344
344
|
|
345
|
-
# rubocop:disable Layout/LineLength
|
346
345
|
# Return random code snippet
|
347
346
|
# @param lang [Symbol] The language of the code snippet
|
348
347
|
# @return [String] A randomly generated code snippet
|
@@ -360,7 +359,6 @@ module RandomWords
|
|
360
359
|
lang ||= code_lang
|
361
360
|
code_snippets[lang.to_sym]
|
362
361
|
end
|
363
|
-
# rubocop:enable Layout/LineLength
|
364
362
|
|
365
363
|
# Generate random markdown
|
366
364
|
# @param settings [Hash] Settings for generating markdown
|
@@ -406,7 +404,7 @@ module RandomWords
|
|
406
404
|
# Generate a random name
|
407
405
|
# @return [String] A randomly generated name
|
408
406
|
def name
|
409
|
-
"#{
|
407
|
+
"#{dbg('NAM')}#{random_name}"
|
410
408
|
end
|
411
409
|
|
412
410
|
private
|
@@ -539,7 +537,7 @@ module RandomWords
|
|
539
537
|
# @example
|
540
538
|
# random_conjunction # Returns a random conjunction
|
541
539
|
def random_conjunction
|
542
|
-
"#{
|
540
|
+
"#{dbg('COC')}#{coordinating_conjunctions.sample}"
|
543
541
|
end
|
544
542
|
|
545
543
|
# Generate a random number with a plural noun
|
@@ -556,65 +554,65 @@ module RandomWords
|
|
556
554
|
end
|
557
555
|
if num == 1 || (RandomWords.testing && !RandomWords.tested.include?('random_noun'))
|
558
556
|
RandomWords.tested << 'random_noun' if RandomWords.testing
|
559
|
-
"#{
|
557
|
+
"#{dbg('NUM')}#{number} #{random_noun}"
|
560
558
|
else
|
561
559
|
RandomWords.tested << 'random_plural_noun' if RandomWords.testing
|
562
|
-
"#{
|
560
|
+
"#{dbg('NUM')}#{number} #{random_plural_noun}"
|
563
561
|
end
|
564
562
|
end
|
565
563
|
|
566
564
|
# Generate a random phrase
|
567
565
|
# @return [String] A randomly selected phrase
|
568
566
|
def random_phrase
|
569
|
-
"#{
|
567
|
+
"#{dbg('PHR')}#{phrases.sample}"
|
570
568
|
end
|
571
569
|
|
572
570
|
# Generate a random noun
|
573
571
|
# @return [String] A randomly selected noun
|
574
572
|
def random_noun
|
575
|
-
"#{
|
573
|
+
"#{dbg('NOU')}#{nouns.sample}"
|
576
574
|
end
|
577
575
|
|
578
576
|
# Generate a random plural noun
|
579
577
|
# @return [String] A randomly selected plural noun
|
580
578
|
def random_plural_noun
|
581
|
-
"#{
|
579
|
+
"#{dbg('PLN')}#{plural_nouns.sample}"
|
582
580
|
end
|
583
581
|
|
584
582
|
# Generate a random verb
|
585
583
|
# @return [String] A randomly selected verb
|
586
584
|
def random_verb
|
587
|
-
"#{
|
585
|
+
"#{dbg('VER')}#{verbs.sample}"
|
588
586
|
end
|
589
587
|
|
590
588
|
# Generate a random plural verb
|
591
589
|
# @return [String] A randomly selected plural verb
|
592
590
|
def random_plural_verb
|
593
|
-
"#{
|
591
|
+
"#{dbg('PLV')}#{plural_verbs.sample}"
|
594
592
|
end
|
595
593
|
|
596
594
|
# Generate a random passive verb
|
597
595
|
# @return [String] A randomly selected passive verb
|
598
596
|
def random_passive_verb
|
599
|
-
"#{
|
597
|
+
"#{dbg('PAV')}#{passive_verbs.sample}"
|
600
598
|
end
|
601
599
|
|
602
600
|
# Generate a random adverb
|
603
601
|
# @return [String] A randomly selected adverb
|
604
602
|
def random_adverb
|
605
|
-
"#{
|
603
|
+
"#{dbg('ADV')}#{adverbs.sample}"
|
606
604
|
end
|
607
605
|
|
608
606
|
# Generate a random adjective
|
609
607
|
# @return [String] A randomly selected adjective
|
610
608
|
def random_adjective
|
611
|
-
"#{
|
609
|
+
"#{dbg('ADJ')}#{adjectives.sample}"
|
612
610
|
end
|
613
611
|
|
614
612
|
# Generate a random article
|
615
613
|
# @return [String] A randomly selected article
|
616
614
|
def random_article
|
617
|
-
"#{
|
615
|
+
"#{dbg('ART')}#{articles.rotate[0]}"
|
618
616
|
end
|
619
617
|
|
620
618
|
# Generate a random article for a noun
|
@@ -640,13 +638,13 @@ module RandomWords
|
|
640
638
|
# Generate a random plural article
|
641
639
|
# @return [String] A randomly selected plural article
|
642
640
|
def random_plural_article
|
643
|
-
"#{
|
641
|
+
"#{dbg('PLA')}#{plural_articles.rotate[0]}"
|
644
642
|
end
|
645
643
|
|
646
644
|
# Generate a random clause
|
647
645
|
# @return [String] A randomly selected clause
|
648
646
|
def random_clause
|
649
|
-
"#{
|
647
|
+
"#{dbg('CLA')}#{clauses.sample}"
|
650
648
|
end
|
651
649
|
|
652
650
|
# Generate a random set of separators
|
@@ -657,25 +655,25 @@ module RandomWords
|
|
657
655
|
# Generate a random separator
|
658
656
|
# @return [String] A randomly selected separator
|
659
657
|
def random_separator
|
660
|
-
"#{
|
658
|
+
"#{dbg('SEP')}#{random_separators.sample}"
|
661
659
|
end
|
662
660
|
|
663
661
|
# Generate a random subordinate conjunction
|
664
662
|
# @return [String] A randomly selected subordinate conjunction
|
665
663
|
def random_subordinate_conjunction
|
666
|
-
"#{
|
664
|
+
"#{dbg('SUC')}#{subordinate_conjunctions.rotate[0]}"
|
667
665
|
end
|
668
666
|
|
669
667
|
# Generate a random coordinating conjunction
|
670
668
|
# @return [String] A randomly selected coordinating conjunction
|
671
669
|
def random_coordinating_conjunction
|
672
|
-
"#{
|
670
|
+
"#{dbg('COC')}#{coordinating_conjunctions.rotate[0]}"
|
673
671
|
end
|
674
672
|
|
675
673
|
# Generate a random preposition
|
676
674
|
# @return [String] A randomly selected preposition
|
677
675
|
def random_preposition
|
678
|
-
"#{
|
676
|
+
"#{dbg('PRE')}#{prepositions.rotate[0]}"
|
679
677
|
end
|
680
678
|
|
681
679
|
# Generate a random prepositional phrase
|
@@ -692,7 +690,7 @@ module RandomWords
|
|
692
690
|
"#{random_article_for_word(noun)} #{noun}"
|
693
691
|
end
|
694
692
|
|
695
|
-
"#{
|
693
|
+
"#{dbg('PRP')}#{preposition} #{phrase}"
|
696
694
|
end
|
697
695
|
|
698
696
|
# Generate a random terminator
|