random-words 1.0.6 → 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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec_status +118 -100
  3. data/.rubocop.yml +4 -1
  4. data/.rubocop_todo.yml +313 -0
  5. data/CHANGELOG.md +26 -1
  6. data/Gemfile +15 -12
  7. data/Gemfile.lock +44 -27
  8. data/README.md +81 -37
  9. data/bin/randw +109 -89
  10. data/lib/random-words/array.rb +27 -7
  11. data/lib/random-words/config.rb +29 -23
  12. data/lib/random-words/generator.rb +42 -25
  13. data/lib/random-words/hash.rb +1 -1
  14. data/lib/random-words/html2markdown.rb +7 -7
  15. data/lib/random-words/lorem-markdown.rb +19 -20
  16. data/lib/random-words/number-to-word.rb +23 -21
  17. data/lib/random-words/source.rb +10 -9
  18. data/lib/random-words/string.rb +22 -17
  19. data/lib/random-words/table-cleanup.rb +3 -3
  20. data/lib/random-words/version.rb +1 -1
  21. data/lib/random-words/words/1984/names.txt +10 -72
  22. data/lib/random-words/words/1984/phrases.txt +16 -0
  23. data/lib/random-words/words/alice/names.txt +10 -74
  24. data/lib/random-words/words/alice/phrases.txt +16 -0
  25. data/lib/random-words/words/bacon/names.txt +53 -73
  26. data/lib/random-words/words/bacon/phrases.txt +20 -0
  27. data/lib/random-words/words/corporate/phrases.txt +29 -0
  28. data/lib/random-words/words/doctor/names.txt +18 -18
  29. data/lib/random-words/words/doctor/phrases.txt +29 -0
  30. data/lib/random-words/words/english/phrases.txt +29 -0
  31. data/lib/random-words/words/foulmouth/articles-plural.txt +3 -1
  32. data/lib/random-words/words/foulmouth/articles-singular.txt +2 -1
  33. data/lib/random-words/words/foulmouth/config.yml +1 -1
  34. data/lib/random-words/words/foulmouth/names.txt +80 -73
  35. data/lib/random-words/words/foulmouth/phrases.txt +30 -0
  36. data/lib/random-words/words/hipster/names.txt +72 -73
  37. data/lib/random-words/words/hipster/phrases.txt +21 -0
  38. data/lib/random-words/words/latin/names.txt +92 -73
  39. data/lib/random-words/words/latin/phrases.txt +16 -0
  40. data/lib/random-words/words/spanish/names.txt +55 -68
  41. data/lib/random-words/words/spanish/phrases.txt +31 -0
  42. data/lib/random-words/words/veggie/names.txt +92 -73
  43. data/lib/random-words/words/veggie/phrases.txt +20 -0
  44. data/lib/random-words.rb +3 -3
  45. data/random-words.gemspec +1 -1
  46. data/src/_README.md +81 -37
  47. metadata +15 -4
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
@@ -48,7 +48,6 @@ module RandomWords
48
48
  rw_source = RandomWords::Source.new(@lang, @source_dir)
49
49
 
50
50
  @dictionary = rw_source.dictionary
51
-
52
51
  end
53
52
 
54
53
  # Tests if a uer dictionary exists
@@ -56,7 +55,9 @@ module RandomWords
56
55
  # @raise [RuntimeError] if the user dictionary is incomplete
57
56
  def user_dictionary_exist?
58
57
  if user_lang_dir
59
- raise "User dictionary for #{@lang} is incomplete. Please run create_user_dictionary." unless all_parts_of_speech?(user_lang_dir, @lang)
58
+ raise "User dictionary for #{@lang} is incomplete. Please run create_user_dictionary." unless all_parts_of_speech?(
59
+ user_lang_dir, @lang
60
+ )
60
61
 
61
62
  true
62
63
  else
@@ -93,11 +94,11 @@ module RandomWords
93
94
  dir ||= @source_dir
94
95
  exists = true
95
96
  SPEECH_PARTS.each do |part|
96
- unless File.exist?(File.join(dir, "#{part}.txt"))
97
- warn "Missing #{File.join(dir, "#{part}.txt")} for #{lang}"
98
- exists = false
99
- break
100
- end
97
+ next if File.exist?(File.join(dir, "#{part}.txt"))
98
+
99
+ warn "Missing #{File.join(dir, "#{part}.txt")} for #{lang}"
100
+ exists = false
101
+ break
101
102
  end
102
103
  CONFIG_FILES.each do |file|
103
104
  unless File.exist?(File.join(dir, "#{file}.yml"))
@@ -112,7 +113,8 @@ module RandomWords
112
113
  # @param lang [String] The language to create the dictionary for
113
114
  # @return [Symbol, nil] The language symbol if successful, nil otherwise
114
115
  def create_user_dictionary(lang = nil)
115
- return lang.to_sym if File.directory?(File.join(config_dir, 'words', lang)) && all_parts_of_speech?(File.join(config_dir, 'words', lang), lang)
116
+ return lang.to_sym if File.directory?(File.join(config_dir, 'words',
117
+ lang)) && all_parts_of_speech?(File.join(config_dir, 'words', lang), lang)
116
118
 
117
119
  lang_dir = File.join(config_dir, 'words', lang)
118
120
 
@@ -132,27 +134,29 @@ module RandomWords
132
134
  target_file = File.join(lang_dir, 'numbers.yml')
133
135
  unless File.exist?(target_file)
134
136
  FileUtils.cp(source_file, target_file)
135
- warn "Created numbers.yml"
137
+ warn 'Created numbers.yml'
136
138
  end
137
139
 
138
140
  # Create the config.yml file if it doesn't exist
139
- target_file = File.join(lang_dir, "config.yml")
141
+ target_file = File.join(lang_dir, 'config.yml')
140
142
 
141
143
  unless File.exist?(target_file)
142
144
  config = {
143
- "name" => lang,
144
- "triggers" => [lang],
145
- "description" => "User dictionary for #{lang}",
145
+ 'name' => lang,
146
+ 'triggers' => [lang],
147
+ 'description' => "User dictionary for #{lang}"
146
148
  }
147
149
  File.write(target_file, config.to_yaml)
148
150
  warn "Created #{target_file}"
149
151
  end
150
152
 
151
- if all_parts_of_speech?(lang_dir, lang) || (RandomWords.testing && !RandomWords.tested.include?('create_user_dictionary'))
152
- RandomWords.tested << 'create_user_dictionary'
153
- warn "Created #{lang} in #{lang_dir}"
154
- lang.to_sym
153
+ unless all_parts_of_speech?(lang_dir, lang) || (RandomWords.testing && !RandomWords.tested.include?('create_user_dictionary'))
154
+ return
155
155
  end
156
+
157
+ RandomWords.tested << 'create_user_dictionary'
158
+ warn "Created #{lang} in #{lang_dir}"
159
+ lang.to_sym
156
160
  end
157
161
 
158
162
  # List all sources available, builtin and custom
@@ -161,13 +165,15 @@ module RandomWords
161
165
  return @sources if @sources
162
166
 
163
167
  @sources = {}
164
- Dir[File.join(__dir__, "words", "*")].each do |dir|
168
+ Dir[File.join(__dir__, 'words', '*')].each do |dir|
165
169
  next unless File.directory?(dir)
170
+
166
171
  name = File.basename(dir)
167
172
  @sources[name] = RandomWords::Source.new(name, dir)
168
173
  end
169
- Dir[File.join(config_dir, "words", "*")].each do |dir|
174
+ Dir[File.join(config_dir, 'words', '*')].each do |dir|
170
175
  next unless File.directory?(dir)
176
+
171
177
  name = File.basename(dir)
172
178
  @sources[name] = RandomWords::Source.new(name, dir)
173
179
  end
@@ -201,7 +207,7 @@ module RandomWords
201
207
  {
202
208
  source: configuration[:source].to_source || :latin,
203
209
  sentence_length: configuration[:length].to_length || :medium,
204
- paragraph_length: configuration[:paragraph_length].to_i || 5,
210
+ paragraph_length: configuration[:paragraph_length].to_i || 5
205
211
  }
206
212
  end
207
213
 
@@ -236,9 +242,9 @@ module RandomWords
236
242
  def create_base_config(config_file)
237
243
  FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
238
244
  config = {
239
- "source" => "latin",
240
- "length" => "medium",
241
- "paragraph_length" => 5,
245
+ 'source' => 'latin',
246
+ 'length' => 'medium',
247
+ 'paragraph_length' => 5
242
248
  }
243
249
  File.write(config_file, config.to_yaml)
244
250
  warn "Created #{config_file}"