random-words 1.0.6 → 1.0.8

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -3
  3. data/.rubocop.yml +4 -1
  4. data/.rubocop_todo.yml +313 -0
  5. data/.vscode/launch.json +26 -0
  6. data/CHANGELOG.md +34 -1
  7. data/Gemfile +15 -12
  8. data/Gemfile.lock +44 -27
  9. data/README.md +81 -37
  10. data/bin/randw +109 -89
  11. data/lib/random-words/array.rb +27 -7
  12. data/lib/random-words/config.rb +29 -23
  13. data/lib/random-words/generator.rb +42 -25
  14. data/lib/random-words/hash.rb +1 -1
  15. data/lib/random-words/html2markdown.rb +7 -7
  16. data/lib/random-words/lorem-markdown.rb +19 -20
  17. data/lib/random-words/number-to-word.rb +23 -21
  18. data/lib/random-words/source.rb +10 -9
  19. data/lib/random-words/string.rb +26 -21
  20. data/lib/random-words/table-cleanup.rb +3 -3
  21. data/lib/random-words/version.rb +1 -1
  22. data/lib/random-words/words/1984/names.txt +10 -72
  23. data/lib/random-words/words/1984/phrases.txt +16 -0
  24. data/lib/random-words/words/alice/names.txt +10 -74
  25. data/lib/random-words/words/alice/phrases.txt +16 -0
  26. data/lib/random-words/words/bacon/names.txt +53 -73
  27. data/lib/random-words/words/bacon/phrases.txt +20 -0
  28. data/lib/random-words/words/corporate/phrases.txt +29 -0
  29. data/lib/random-words/words/doctor/names.txt +18 -18
  30. data/lib/random-words/words/doctor/phrases.txt +29 -0
  31. data/lib/random-words/words/english/phrases.txt +29 -0
  32. data/lib/random-words/words/foulmouth/articles-plural.txt +3 -1
  33. data/lib/random-words/words/foulmouth/articles-singular.txt +2 -1
  34. data/lib/random-words/words/foulmouth/config.yml +1 -1
  35. data/lib/random-words/words/foulmouth/names.txt +80 -73
  36. data/lib/random-words/words/foulmouth/phrases.txt +30 -0
  37. data/lib/random-words/words/hipster/names.txt +72 -73
  38. data/lib/random-words/words/hipster/phrases.txt +21 -0
  39. data/lib/random-words/words/latin/names.txt +92 -73
  40. data/lib/random-words/words/latin/phrases.txt +16 -0
  41. data/lib/random-words/words/spanish/names.txt +55 -68
  42. data/lib/random-words/words/spanish/phrases.txt +31 -0
  43. data/lib/random-words/words/veggie/names.txt +92 -73
  44. data/lib/random-words/words/veggie/phrases.txt +20 -0
  45. data/lib/random-words.rb +3 -3
  46. data/random-words.gemspec +1 -1
  47. data/src/_README.md +81 -37
  48. metadata +16 -5
  49. data/.rspec_status +0 -148
data/README.md CHANGED
@@ -16,25 +16,38 @@ you use [Homebrew](https://brew.sh).
16
16
 
17
17
  ### CLI
18
18
 
19
- The gem installs a binary `randw`. It can generate random characters, sentences, paragraphs, and passwords.
19
+ The gem installs a binary `randw`. It can generate random
20
+ characters, sentences, paragraphs, markdown, html, and
21
+ passwords.
20
22
 
21
23
  ```console
22
24
  Usage: randw [options]
23
25
  OPTIONS:
24
- -S, --source [SOURCE] Specify the source language (default: latin)
25
- -l [short|medium|long|very_long],
26
- --length Specify the length of the sentence
27
- --graf-length [NUMBER] Specify the number of sentences in a paragraph
28
- -s, --sentences [NUMBER] Generate random sentences
26
+ -S, --source SOURCE Specify the source language (default: latin)
27
+ -l, --length LENGTH Specify the length of the sentence [short|medium|long|very_long]
28
+ --graf-length NUMBER Specify the number of sentences in a paragraph
29
+ --[no-]extended Specify whether to use extended punctuation in generated text
29
30
  GENERATORS:
30
- -p, --paragraphs [NUMBER] Generate random paragraphs
31
- -w, --words [NUMBER] Generate random words
32
- -c, --characters [NUMBER] Generate random characters
33
- -m, --markdown SETTINGS Generate random markdown text, comma separated string like "latin,10,all"
34
- --password Generate a random password
31
+ -s, --sentences [NUMBER] Generate NUMBER of random sentences (default: 3)
32
+ -p, --paragraphs [NUMBER] Generate NUMBER of random paragraphs (default: 3)
33
+ -w, --words [NUMBER] Generate NUMBER of random words (default: 10)
34
+ -c, --characters [NUMBER] Generate random characters of length (default: 100)
35
+ -m, --markdown [SETTINGS] Generate random markdown text, comma separated string like "latin,10,all"
36
+ dec: add em and strong
37
+ link: add links
38
+ ul: add unordered lists
39
+ ol: add ordered lists
40
+ dl: add definition lists
41
+ bq: add block quotes
42
+ code: add code spans and block
43
+ mark: add ==highlights==
44
+ headers: add headlines
45
+ image: add images
46
+ table: add tables
47
+ -H, --html [SETTINGS] Generate random html text, comma separated string like "latin,10,all"
48
+ --password [LENGTH] Generate a random password of LENGTH (default: 20)
35
49
  PASSWORD OPTIONS:
36
- --separator [CHAR] Specify the separator character for the password
37
- --[no-]extended Specify whether to use extended punctuation in generated text
50
+ --separator CHAR Specify the separator character for the password (default: " ")
38
51
  -n, --[no-]whitespace Specify whether to remove whitespace in generated text (characters only)
39
52
  DICTIONARIES:
40
53
  --list-dictionaries List available dictionaries
@@ -78,9 +91,23 @@ The number of elements inserted depends on the length you specify.
78
91
 
79
92
  Example commands:
80
93
 
81
- $ randw -m "latin/10/ol/dl/table"
82
- $ randw -m "english/5/all"
94
+ ```console
95
+ $ randw -m "latin/1/short/ol"
96
+
97
+ Illa brevis muros potior arcesso, apud multae octo centum nonaginta octo nodum! Haec ruosus misericordia mox contendo, apud nullus fors.
98
+
99
+
100
+ 1. Hoc cognatus opus facile complor latus discendo
101
+ 2. Aliqua apparens census quod nego
102
+ 3. Nullus salvus dux apud habeo spectabilis
103
+ 4. Quaedam sensus regnum cura gaudeo ornatus faeneo mox
104
+
105
+ $ randw -m "english,5,all"
83
106
 
107
+ # Any shiny napkin effectively picks
108
+
109
+ Neither sudden lake exceedingly works, outside a clarity even if which is a source of _an_ strength even if which holds _one subtle horse_ the future. Any lovable tank remarkabl...
110
+ ```
84
111
 
85
112
  #### Creating A New Dictionary
86
113
 
@@ -118,9 +145,11 @@ clauses.txt
118
145
  config.yml
119
146
  conjunctions-coordinating.txt
120
147
  conjunctions-subordinate.txt
148
+ names.txt
121
149
  nouns-plural.txt
122
150
  nouns-singular.txt
123
151
  numbers.txt
152
+ phrases.txt
124
153
  prepositions.txt
125
154
  terminators.txt
126
155
  verbs-passive.txt
@@ -128,8 +157,34 @@ verbs-plural.txt
128
157
  verbs-singular.txt
129
158
  ```
130
159
 
160
+ ##### Language Configuration
161
+
162
+ The `config.yml` file in a language directory is a simple
163
+ YAML configuration. It contains the keys:
164
+
165
+ ```yaml
166
+ ---
167
+ name: english
168
+ description: English words
169
+ triggers: [english]
170
+ ```
171
+
172
+ A default configuration file will be created when running `--create-dictionary` with the CLI.
173
+
174
+ - `name`: The name of the dictionary
175
+
176
+ This should be the same as the directory name in most cases
177
+ - `description`: Just used for display when running `--list-dictionaries`
178
+ - `triggers`: An array of triggers that can be used to trigger the language.
179
+
180
+ For example, the `bacon` language has the triggers `[bacon, meat, carnivore]`, so you can use `randw -S meat` on the command line (or with the library).
181
+
182
+
183
+
184
+ ##### Terminators
185
+
131
186
  The `terminators.txt` file contains pairs of punctuation,
132
- separated by commas, one per line. If a sentene terminator
187
+ separated by commas, one per line. If a sentence terminator
133
188
  doesn't have opening punctuation, start the line with a
134
189
  comma. More than one character can be used in either side of
135
190
  the pair. For example, to create a double quoted sentence
@@ -154,30 +209,19 @@ default terminator.txt files, the period, question mark, and
154
209
  exclamation point are repeated multiple times to make them
155
210
  the most likely to be used.
156
211
 
212
+ ##### Names
157
213
 
158
- ##### Language Configuration
159
-
160
- The `config.yml` file in a language directory is a simple
161
- YAML configuration. It contains the keys:
214
+ The `names.txt` file is just used when creating block quotes
215
+ in Markdown or HTML output. Sections are split by blank
216
+ lines: first names, last names, and optionally full names.
217
+ If the first line contains characters other than letters,
218
+ single quotes, and dashes, it will be assumed that you've
219
+ skipped straight to full names and those will be used
220
+ instead of generating random combinations.
162
221
 
163
- ```yaml
164
- ---
165
- name: english
166
- description: English words
167
- triggers: [english]
168
- ```
169
-
170
- A default configuration file will be created when running `--create-dictionary` with the CLI.
171
-
172
- - `name`: The name of the dictionary
173
-
174
- This should be the same as the directory name in most cases
175
- - `description`: Just used for display when running `--list-dictionaries`
176
- - `triggers`: An array of triggers that can be used to trigger the language.
177
-
178
- For example, the `bacon` language has the triggers `[bacon, meat, carnivore]`, so you can use `randw -S meat` on the command line (or with the library).
222
+ #### Language Notes
179
223
 
180
- > RandomWords loosely uses English rules for sentence construction, so non-English languages will likely generate even more nonsensical strings.
224
+ RandomWords loosely uses English rules for sentence construction, so non-English languages will likely generate even more nonsensical strings.
181
225
 
182
226
  If you create a fun dictionary, please let me know (or make a PR) and I'll gladly include (most) new dictionaries in the main distribution.
183
227
 
data/bin/randw CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../lib/random-words'
5
- require 'optparse'
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
@@ -15,7 +16,7 @@ module RandomWords
15
16
  counter: :boldcyan,
16
17
  marker: :boldgreen,
17
18
  bracket: :cyan,
18
- language: :boldmagenta
19
+ language: :boldmagenta,
19
20
  }
20
21
  @sources = @sentence_generator.sources.keys.map(&:to_s)
21
22
  end
@@ -30,15 +31,15 @@ module RandomWords
30
31
  magenta: 35,
31
32
  cyan: 36,
32
33
  white: 37,
33
- boldblack: '1;30',
34
- boldred: '1;31',
35
- boldgreen: '1;32',
36
- boldyellow: '1;33',
37
- boldblue: '1;34',
38
- boldmagenta: '1;35',
39
- boldcyan: '1;36',
40
- boldwhite: '1;37',
41
- 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,
42
43
  }
43
44
  end
44
45
 
@@ -50,13 +51,13 @@ module RandomWords
50
51
 
51
52
  def header_1(text)
52
53
  puts colorize_text("\n\n#{text}", :boldgreen)
53
- puts colorize_text('=' * text.length, :boldgreen)
54
+ puts colorize_text("=" * text.length, :boldgreen)
54
55
  puts "\n"
55
56
  end
56
57
 
57
58
  def header_2(text)
58
59
  puts colorize_text("\n\n#{text}", :boldyellow)
59
- puts colorize_text('-' * text.length, :boldyellow)
60
+ puts colorize_text("-" * text.length, :boldyellow)
60
61
  puts "\n"
61
62
  end
62
63
 
@@ -83,7 +84,7 @@ module RandomWords
83
84
  def combined_sentences(length = nil)
84
85
  number_of_sentences = length || 2
85
86
 
86
- header_1('Random Combined Sentences:')
87
+ header_1("Random Combined Sentences:")
87
88
  @sources.count.times do |i|
88
89
  @sentence_generator.source = @sources[i - 1]
89
90
  @sentence_generator.sentence_length = :medium
@@ -92,20 +93,20 @@ module RandomWords
92
93
  s = @sentence_generator.sentence
93
94
  puts "#{marker} #{text(s)}"
94
95
  puts counter("#{s.split(/ /).count} words, #{s.length} characters")
95
- puts colorize_text(' ' * 2, :boldwhite)
96
+ puts colorize_text(" " * 2, :boldwhite)
96
97
  end
97
98
  end
98
99
 
99
100
  def random_sentences
100
- header_1('Random Sentences')
101
- @sentence_generator.lengths.keys.each_with_index do |length, index|
101
+ header_1("Random Sentences")
102
+ @sentence_generator.lengths.keys.each_with_index do |length, index|
102
103
  @sentence_generator.source = @sources[index]
103
104
  sentence(length)
104
105
  end
105
106
  end
106
107
 
107
108
  def random_paragraphs
108
- header_1('Random Paragraphs')
109
+ header_1("Random Paragraphs")
109
110
  @sentence_generator.lengths.keys.each_with_index do |length, index|
110
111
  @sentence_generator.source = @sources[index]
111
112
  paragraphs(length, 3)
@@ -132,7 +133,7 @@ module RandomWords
132
133
 
133
134
  # Generate and print specified number of characters
134
135
  def random_characters
135
- header_1('Random Characters (exact length)')
136
+ header_1("Random Characters (exact length)")
136
137
  [20, 50, 120, 200, 500].each_with_index do |i, index|
137
138
  @sentence_generator.source = @sources[index]
138
139
  chars = @sentence_generator.characters(i, whole_words: true)
@@ -143,7 +144,7 @@ module RandomWords
143
144
  max_characters = [15, 25, 53, 110, 600]
144
145
  min_characters = [10, 20, 50, 100, 500]
145
146
 
146
- header_1('Random Characters (length range)')
147
+ header_1("Random Characters (length range)")
147
148
  max_characters.count.times do |i|
148
149
  @sentence_generator.source = @sources[i]
149
150
  chars = @sentence_generator.characters(min_characters[i], max_characters[i], whole_words: true)
@@ -153,7 +154,7 @@ module RandomWords
153
154
  end
154
155
 
155
156
  def marker
156
- colorize_text('', @colors[:marker])
157
+ colorize_text("", @colors[:marker])
157
158
  end
158
159
 
159
160
  def text(text)
@@ -163,8 +164,7 @@ module RandomWords
163
164
  def language
164
165
  "#{colorize_text("(",
165
166
  @colors[:bracket])}#{colorize_text("#{@sentence_generator.source}", @colors[:language])}#{colorize_text(")",
166
- @colors[:bracket])}"
167
-
167
+ @colors[:bracket])}"
168
168
  end
169
169
 
170
170
  def counter(length)
@@ -192,91 +192,104 @@ end
192
192
  method: nil,
193
193
  debug: false,
194
194
  whitespace: true,
195
- separator: ' ',
196
- use_extended_punctuation: false
195
+ separator: " ",
196
+ use_extended_punctuation: false,
197
197
  }
198
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
+
199
213
  OptionParser.new do |opts|
200
- opts.banner = 'Usage: randw [options]'
214
+ opts.banner = "Usage: randw [options]"
201
215
 
202
- opts.separator 'OPTIONS:'
216
+ opts.separator "OPTIONS:"
203
217
 
204
- opts.on('-S', '--source SOURCE', 'Specify the source language (default: latin)') do |source|
218
+ opts.on("-S", "--source SOURCE", "Specify the source language (default: latin)") do |source|
205
219
  @options[:source] = source.to_source
206
220
  end
207
221
 
208
- opts.on('-l', '--length LENGTH', 'Specify the length of the sentence [short|medium|long|very_long]') do |length|
222
+ opts.on("-l", "--length LENGTH", "Specify the length of the sentence [short|medium|long|very_long]") do |length|
209
223
  @options[:length] = case length
210
- when /^s/
211
- :short
212
- when /^l/
213
- :long
214
- when /^v/
215
- :very_long
216
- else
217
- :medium
218
- end
224
+ when /^s/
225
+ :short
226
+ when /^l/
227
+ :long
228
+ when /^v/
229
+ :very_long
230
+ else
231
+ :medium
232
+ end
219
233
  end
220
234
 
221
- opts.on('--graf-length NUMBER', 'Specify the number of sentences in a paragraph') do |length|
235
+ opts.on("--graf-length NUMBER", "Specify the number of sentences in a paragraph") do |length|
222
236
  @options[:paragraph_length] = length.to_i
223
237
  end
224
238
 
225
- opts.on('--[no-]extended', 'Specify whether to use extended punctuation in generated text') do |value|
239
+ opts.on("--[no-]extended", "Specify whether to use extended punctuation in generated text") do |value|
226
240
  @options[:use_extended_punctuation] = value
227
241
  end
228
242
 
229
- opts.separator 'GENERATORS:'
243
+ opts.separator "GENERATORS:"
230
244
 
231
- opts.on('-s', '--sentences [NUMBER]', 'Generate NUMBER of random sentences (default: 3)') do |number|
245
+ opts.on("-s", "--sentences [NUMBER]", "Generate NUMBER of random sentences (default: 3)") do |number|
232
246
  @options[:method] = :sentences
233
247
  @options[:count] = number&.to_i || 3
234
248
  end
235
249
 
236
-
237
- opts.on('-p', '--paragraphs [NUMBER]', 'Generate NUMBER of random paragraphs (default: 3)') do |number|
250
+ opts.on("-p", "--paragraphs [NUMBER]", "Generate NUMBER of random paragraphs (default: 3)") do |number|
238
251
  @options[:method] = :paragraphs
239
252
  @options[:count] = number&.to_i || 3
240
253
  end
241
254
 
242
- opts.on('-w', '--words [NUMBER]', 'Generate NUMBER of random words (default: 10)') do |number|
255
+ opts.on("-w", "--words [NUMBER]", "Generate NUMBER of random words (default: 10)") do |number|
243
256
  @options[:method] = :words
244
257
  @options[:count] = number&.to_i || 10
245
258
  end
246
259
 
247
- opts.on('-c', '--characters [NUMBER]', 'Generate random characters of length (default: 100)') do |number|
260
+ opts.on("-c", "--characters [NUMBER]", "Generate random characters of length (default: 100)") do |number|
248
261
  @options[:method] = :characters
249
262
  @options[:count] = number&.to_i || 100
250
263
  end
251
264
 
252
- opts.on('-m', '--markdown [SETTINGS]', 'Generate random markdown text, comma separated string like "latin,10,all"') do |settings|
265
+ opts.on("-m", "--markdown [SETTINGS]", "Generate random markdown text, comma separated string like \"latin,10,all\"\n#{markdown_help}") do |settings|
253
266
  @options[:method] = :markdown
254
- @options[:markdown_settings] = settings || 'latin,10,all'
267
+ @options[:markdown_settings] = settings || "latin,10,all"
255
268
  end
256
269
 
257
- opts.on('-H', '--html [SETTINGS]', 'Generate random html text, comma separated string like "latin,10,all"') do |settings|
270
+ opts.on("-H", "--html [SETTINGS]", "Generate random html text, comma separated string like \"latin,10,all\"") do |settings|
258
271
  @options[:method] = :html
259
- @options[:markdown_settings] = settings || 'latin,10,all'
272
+ @options[:markdown_settings] = settings || "latin,10,all"
260
273
  end
261
274
 
262
- opts.on('--password [LENGTH]', 'Generate a random password of LENGTH (default: 20)') do |len|
275
+ opts.on("--password [LENGTH]", "Generate a random password of LENGTH (default: 20)") do |len|
263
276
  @options[:method] = :password
264
277
  @options[:count] = len&.to_i || 20
265
278
  end
266
279
 
267
- opts.separator 'PASSWORD OPTIONS:'
280
+ opts.separator "PASSWORD OPTIONS:"
268
281
 
269
- opts.on('--separator CHAR', 'Specify the separator character for the password (default: " ")') do |separator|
282
+ opts.on("--separator CHAR", 'Specify the separator character for the password (default: " ")') do |separator|
270
283
  @options[:separator] = separator
271
284
  end
272
285
 
273
- opts.on('-n', '--[no-]whitespace', 'Specify whether to remove whitespace in generated text (characters only)') do |value|
286
+ opts.on("-n", "--[no-]whitespace", "Specify whether to remove whitespace in generated text (characters only)") do |value|
274
287
  @options[:whitespace] = value
275
288
  end
276
289
 
277
- opts.separator 'DICTIONARIES:'
290
+ opts.separator "DICTIONARIES:"
278
291
 
279
- opts.on('--list-dictionaries', 'List available dictionaries') do
292
+ opts.on("--list-dictionaries", "List available dictionaries") do
280
293
  @rw = RandomWords::Generator.new(:latin)
281
294
 
282
295
  @rw.sources.each do |k, v|
@@ -287,29 +300,29 @@ OptionParser.new do |opts|
287
300
  Process.exit 0
288
301
  end
289
302
 
290
- opts.on('--create-dictionary [NAME]', 'Create a new dictionary') do |name|
303
+ opts.on("--create-dictionary [NAME]", "Create a new dictionary") do |name|
291
304
  @rw = RandomWords::Generator.new(:latin)
292
305
  @rw.create_dictionary(name)
293
306
  Process.exit 0
294
307
  end
295
308
 
296
- opts.separator 'OTHER OPTIONS:'
309
+ opts.separator "OTHER OPTIONS:"
297
310
 
298
- opts.on('-d', '--debug', 'Enable debug mode, displays sentence/word/character counts') do
311
+ opts.on("-d", "--debug", "Enable debug mode, displays sentence/word/character counts") do
299
312
  @options[:debug] = true
300
313
  end
301
314
 
302
- opts.on('-h', '--help', 'Display this help message') do
315
+ opts.on("-h", "--help", "Display this help message") do
303
316
  puts opts
304
317
  exit
305
318
  end
306
319
 
307
- opts.on('-v', '--version', 'Display the version') do
320
+ opts.on("-v", "--version", "Display the version") do
308
321
  puts "RandomWords v#{RandomWords::VERSION}"
309
322
  exit
310
323
  end
311
324
 
312
- opts.on('-t', '--test', 'Run the full debug test') do
325
+ opts.on("-t", "--test", "Run the full debug test") do
313
326
  @options[:method] = :test
314
327
  @options[:debug] = true
315
328
  end
@@ -334,7 +347,7 @@ def markdown_settings(settings)
334
347
  grafs: 10,
335
348
  sentences: base_config[:paragraph_length],
336
349
  length: base_config[:sentence_length],
337
- decorate: true,
350
+ decorate: false,
338
351
  link: false,
339
352
  ul: false,
340
353
  ol: false,
@@ -343,16 +356,17 @@ def markdown_settings(settings)
343
356
  code: false,
344
357
  mark: false,
345
358
  headers: false,
346
- table: false
359
+ table: false,
347
360
  }
348
361
  sources = []
349
362
  RandomWords::Generator.new(:latin).sources.each { |k, v| sources.concat(v.names.map(&:to_s)) }
350
363
 
351
364
  markdown_options = defaults.dup
352
365
  settings = settings.split(%r{[,/.\|]}).map(&:strip)
366
+
353
367
  settings.each do |setting|
354
368
  case setting
355
- when /^a(ll)?/
369
+ when /^all$/
356
370
  new_options = {
357
371
  decorate: true,
358
372
  link: true,
@@ -364,35 +378,37 @@ def markdown_settings(settings)
364
378
  mark: true,
365
379
  headers: true,
366
380
  image: true,
367
- table: true
381
+ table: true,
368
382
  }
369
383
  markdown_options.merge!(new_options)
370
384
  when Regexp.union(sources)
371
385
  markdown_options[:source] = setting.to_source
372
386
  when /^\d+$/
373
387
  markdown_options[:grafs] = setting.to_i
374
- when /^dec/
388
+ when 'dec', 'decorate'
375
389
  markdown_options[:decorate] = true
376
- when /^link/
390
+ when 'link'
377
391
  markdown_options[:link] = true
378
- when /^ul/
392
+ when 'ul'
379
393
  markdown_options[:ul] = true
380
- when /^ol/
394
+ when 'ol'
381
395
  markdown_options[:ol] = true
382
- when /^dl/
396
+ when 'dl'
383
397
  markdown_options[:dl] = true
384
- when /^bq/
398
+ when 'bq', 'blockquote'
385
399
  markdown_options[:bq] = true
386
- when /^co/
400
+ when 'code'
387
401
  markdown_options[:code] = true
388
- when /^ma/
402
+ when 'mark'
389
403
  markdown_options[:mark] = true
390
- when /^h/
404
+ when 'header', 'h'
391
405
  markdown_options[:headers] = true
392
- when /^t(a|bl)/
406
+ when 'table', 't'
393
407
  markdown_options[:table] = true
394
- when /^[smlv]/
408
+ when 'short', 's', 'medium', 'med', 'm', 'long', 'l', 'very_long', 'vl'
395
409
  markdown_options[:length] = setting.to_length
410
+ else
411
+ markdown_options[:source] = setting.to_source
396
412
  end
397
413
  end
398
414
 
@@ -410,21 +426,21 @@ when :sentences
410
426
  total = {
411
427
  sentences: @options[:count],
412
428
  words: 0,
413
- characters: 0
429
+ characters: 0,
414
430
  }
415
431
  # @options[:count].times do
416
- s = @rw.sentences(@options[:count]).join(' ')
417
- total[:words] += s.split(/ /).count
418
- total[:characters] += s.length
419
- print s
420
- debug "#{s.split(/ /).count}w, #{s.length}c"
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"
421
437
  # end
422
438
  debug "Total: #{total[:sentences]}s, #{total[:words]}w, #{total[:characters]}c"
423
439
  when :paragraphs
424
440
  total = {
425
441
  sentences: 0,
426
442
  words: 0,
427
- characters: 0
443
+ characters: 0,
428
444
  }
429
445
  @options[:count].times do
430
446
  p = @rw.paragraph
@@ -450,14 +466,18 @@ when :markdown, :html
450
466
  @rw.sentence_length = settings[:length] || :medium
451
467
  @rw.paragraph_length = settings[:sentences] || 5
452
468
  @rw.use_extended_punctuation = settings[:use_extended_punctuation] || false
453
- puts @rw.html(settings)
469
+ if @options[:method] == :markdown
470
+ puts @rw.markdown(settings)
471
+ else
472
+ puts @rw.html(settings)
473
+ end
454
474
  when :password
455
475
  p = @rw.characters(20, whitespace: @options[:whitespace])
456
476
 
457
477
  m = p.match(/[oleats]/i)
458
478
  if m
459
479
  num_char = m.begin(0)
460
- char = m[0].tr('oleats', '013475')
480
+ char = m[0].tr("oleats", "013475")
461
481
  else
462
482
  num_char = p.length
463
483
  char = rand(10).to_s
@@ -468,7 +488,7 @@ when :password
468
488
  cap_char = rand(20) while p[cap_char] !~ /[a-z]/
469
489
  p[cap_char] = p[cap_char].upcase
470
490
 
471
- tail_char = p =~ /[^a-z0-9]/i ? '' : %w[! @ # $ % ^ & * ( ) _ + - = ; : < > , . ? /].sample
491
+ tail_char = p =~ /[^a-z0-9]/i ? "" : %w[! @ # $ % ^ & * ( ) _ + - = ; : < > , . ? /].sample
472
492
 
473
493
  print p.gsub(/ /, @options[:separator]) + tail_char
474
494
  debug "#{p.split(@options[:separator]).count}w, #{p.length}c"
@@ -476,5 +496,5 @@ when :test
476
496
  t = RandomWords::Terminal.new(@options[:source])
477
497
  t.print_test
478
498
  else
479
- puts 'Please specify a valid method: sentences, paragraphs, words, or characters.'
499
+ puts "Please specify a valid method: sentences, paragraphs, words, or characters."
480
500
  end
@@ -33,19 +33,39 @@ module RandomWords
33
33
  def split_names
34
34
  first_names = []
35
35
  last_names = []
36
+ full_names = []
36
37
  first_names_ended = false
38
+ last_names_ended = false
39
+
40
+ sections = [[]]
41
+ idx = 0
37
42
  each do |line|
38
- if line.strip =~ /^[\w-]+$/ && !first_names_ended
39
- first_names << line
40
- elsif first_names_ended
41
- last_names << line
43
+ if line.strip.empty? || line !~ /^[[:word:]]/i
44
+ idx += 1
45
+ sections[idx] = []
42
46
  else
43
- first_names_ended = true
47
+ sections[idx] << line.strip
44
48
  end
45
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
+
46
65
  first_names.delete_if(&:empty?)
47
66
  last_names.delete_if(&:empty?)
48
- [first_names, last_names]
67
+ full_names.delete_if(&:empty?)
68
+ [first_names, last_names, full_names]
49
69
  end
50
70
  end
51
- end
71
+ end