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.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec_status +166 -39
  3. data/.rubocop.yml +4 -0
  4. data/.rubocop_todo.yml +313 -0
  5. data/CHANGELOG.md +67 -0
  6. data/Gemfile +15 -12
  7. data/Gemfile.lock +46 -26
  8. data/README.md +208 -15
  9. data/bin/randw +258 -92
  10. data/lib/random-words/array.rb +71 -0
  11. data/lib/random-words/config.rb +254 -0
  12. data/lib/random-words/generator.rb +257 -94
  13. data/lib/random-words/hash.rb +16 -0
  14. data/lib/random-words/html2markdown.rb +205 -0
  15. data/lib/random-words/lorem-markdown.rb +397 -0
  16. data/lib/random-words/number-to-word.rb +139 -0
  17. data/lib/random-words/source.rb +106 -0
  18. data/lib/random-words/string.rb +224 -45
  19. data/lib/random-words/table-cleanup.rb +210 -0
  20. data/lib/random-words/version.rb +1 -1
  21. data/lib/random-words/words/1984/adjectives.txt +103 -0
  22. data/lib/random-words/words/1984/adverbs.txt +92 -0
  23. data/lib/random-words/words/1984/articles-plural.txt +10 -0
  24. data/lib/random-words/words/1984/articles-singular.txt +10 -0
  25. data/lib/random-words/words/1984/clauses.txt +79 -0
  26. data/lib/random-words/words/1984/config.yml +4 -0
  27. data/lib/random-words/words/1984/conjunctions-coordinating.txt +20 -0
  28. data/lib/random-words/words/1984/conjunctions-subordinate.txt +29 -0
  29. data/lib/random-words/words/1984/names.txt +12 -0
  30. data/lib/random-words/words/1984/nouns-plural.txt +89 -0
  31. data/lib/random-words/words/1984/nouns-singular.txt +74 -0
  32. data/lib/random-words/words/1984/numbers.yml +5 -0
  33. data/lib/random-words/words/1984/phrases.txt +16 -0
  34. data/lib/random-words/words/1984/prepositions.txt +89 -0
  35. data/lib/random-words/words/1984/terminators.txt +16 -0
  36. data/lib/random-words/words/1984/verbs-passive.txt +83 -0
  37. data/lib/random-words/words/1984/verbs-plural.txt +91 -0
  38. data/lib/random-words/words/1984/verbs-singular.txt +110 -0
  39. data/lib/random-words/words/alice/adjectives.txt +80 -0
  40. data/lib/random-words/words/alice/adverbs.txt +87 -0
  41. data/lib/random-words/words/alice/articles-plural.txt +10 -0
  42. data/lib/random-words/words/alice/articles-singular.txt +10 -0
  43. data/lib/random-words/words/alice/clauses.txt +81 -0
  44. data/lib/random-words/words/alice/config.yml +4 -0
  45. data/lib/random-words/words/alice/conjunctions-coordinating.txt +20 -0
  46. data/lib/random-words/words/alice/conjunctions-subordinate.txt +29 -0
  47. data/lib/random-words/words/alice/names.txt +10 -0
  48. data/lib/random-words/words/alice/nouns-plural.txt +95 -0
  49. data/lib/random-words/words/alice/nouns-singular.txt +82 -0
  50. data/lib/random-words/words/alice/numbers.yml +5 -0
  51. data/lib/random-words/words/alice/phrases.txt +16 -0
  52. data/lib/random-words/words/alice/prepositions.txt +45 -0
  53. data/lib/random-words/words/alice/terminators.txt +16 -0
  54. data/lib/random-words/words/alice/verbs-passive.txt +495 -0
  55. data/lib/random-words/words/alice/verbs-plural.txt +115 -0
  56. data/lib/random-words/words/alice/verbs-singular.txt +97 -0
  57. data/lib/random-words/words/bacon/clauses.txt +592 -592
  58. data/lib/random-words/words/bacon/config.yml +4 -0
  59. data/lib/random-words/words/bacon/conjunctions-coordinating.txt +20 -0
  60. data/lib/random-words/words/bacon/names.txt +54 -0
  61. data/lib/random-words/words/bacon/numbers.yml +5 -0
  62. data/lib/random-words/words/bacon/phrases.txt +20 -0
  63. data/lib/random-words/words/bacon/prepositions.txt +45 -0
  64. data/lib/random-words/words/bacon/terminators.txt +16 -0
  65. data/lib/random-words/words/corporate/config.yml +4 -0
  66. data/lib/random-words/words/corporate/conjunctions-coordinating.txt +20 -0
  67. data/lib/random-words/words/corporate/names.txt +74 -0
  68. data/lib/random-words/words/corporate/numbers.yml +5 -0
  69. data/lib/random-words/words/corporate/phrases.txt +29 -0
  70. data/lib/random-words/words/corporate/prepositions.txt +45 -0
  71. data/lib/random-words/words/corporate/terminators.txt +16 -0
  72. data/lib/random-words/words/doctor/adjectives.txt +92 -0
  73. data/lib/random-words/words/doctor/adverbs.txt +92 -0
  74. data/lib/random-words/words/doctor/articles-plural.txt +10 -0
  75. data/lib/random-words/words/doctor/articles-singular.txt +10 -0
  76. data/lib/random-words/words/doctor/clauses.txt +83 -0
  77. data/lib/random-words/words/doctor/config.yml +10 -0
  78. data/lib/random-words/words/doctor/conjunctions-coordinating.txt +20 -0
  79. data/lib/random-words/words/doctor/conjunctions-subordinate.txt +29 -0
  80. data/lib/random-words/words/doctor/names.txt +74 -0
  81. data/lib/random-words/words/doctor/nouns-plural.txt +84 -0
  82. data/lib/random-words/words/doctor/nouns-singular.txt +84 -0
  83. data/lib/random-words/words/doctor/numbers.yml +5 -0
  84. data/lib/random-words/words/doctor/phrases.txt +29 -0
  85. data/lib/random-words/words/doctor/prepositions.txt +45 -0
  86. data/lib/random-words/words/doctor/terminators.txt +16 -0
  87. data/lib/random-words/words/doctor/verbs-passive.txt +83 -0
  88. data/lib/random-words/words/doctor/verbs-plural.txt +88 -0
  89. data/lib/random-words/words/doctor/verbs-singular.txt +83 -0
  90. data/lib/random-words/words/english/clauses.txt +592 -592
  91. data/lib/random-words/words/english/config.yml +4 -0
  92. data/lib/random-words/words/english/conjunctions-coordinating.txt +20 -0
  93. data/lib/random-words/words/english/names.txt +74 -0
  94. data/lib/random-words/words/english/numbers.yml +5 -0
  95. data/lib/random-words/words/english/phrases.txt +29 -0
  96. data/lib/random-words/words/english/prepositions.txt +45 -0
  97. data/lib/random-words/words/english/terminators.txt +16 -0
  98. data/lib/random-words/words/english/verbs-plural.txt +1 -0
  99. data/lib/random-words/words/english/verbs-singular.txt +1 -0
  100. data/lib/random-words/words/foulmouth/adjectives.txt +89 -0
  101. data/lib/random-words/words/foulmouth/adverbs.txt +97 -0
  102. data/lib/random-words/words/foulmouth/articles-plural.txt +12 -0
  103. data/lib/random-words/words/foulmouth/articles-singular.txt +11 -0
  104. data/lib/random-words/words/foulmouth/clauses.txt +74 -0
  105. data/lib/random-words/words/foulmouth/config.yml +4 -0
  106. data/lib/random-words/words/foulmouth/conjunctions-coordinating.txt +20 -0
  107. data/lib/random-words/words/foulmouth/conjunctions-subordinate.txt +29 -0
  108. data/lib/random-words/words/foulmouth/names.txt +81 -0
  109. data/lib/random-words/words/foulmouth/nouns-plural.txt +96 -0
  110. data/lib/random-words/words/foulmouth/nouns-singular.txt +99 -0
  111. data/lib/random-words/words/foulmouth/numbers.yml +5 -0
  112. data/lib/random-words/words/foulmouth/phrases.txt +30 -0
  113. data/lib/random-words/words/foulmouth/prepositions.txt +35 -0
  114. data/lib/random-words/words/foulmouth/terminators.txt +16 -0
  115. data/lib/random-words/words/foulmouth/verbs-passive.txt +143 -0
  116. data/lib/random-words/words/foulmouth/verbs-plural.txt +91 -0
  117. data/lib/random-words/words/foulmouth/verbs-singular.txt +104 -0
  118. data/lib/random-words/words/hipster/adjectives.txt +100 -0
  119. data/lib/random-words/words/hipster/adverbs.txt +89 -0
  120. data/lib/random-words/words/hipster/articles-plural.txt +10 -0
  121. data/lib/random-words/words/hipster/articles-singular.txt +10 -0
  122. data/lib/random-words/words/hipster/clauses.txt +180 -0
  123. data/lib/random-words/words/hipster/config.yml +4 -0
  124. data/lib/random-words/words/hipster/conjunctions-coordinating.txt +20 -0
  125. data/lib/random-words/words/hipster/conjunctions-subordinate.txt +29 -0
  126. data/lib/random-words/words/hipster/names.txt +73 -0
  127. data/lib/random-words/words/hipster/nouns-plural.txt +96 -0
  128. data/lib/random-words/words/hipster/nouns-singular.txt +100 -0
  129. data/lib/random-words/words/hipster/numbers.yml +5 -0
  130. data/lib/random-words/words/hipster/phrases.txt +21 -0
  131. data/lib/random-words/words/hipster/prepositions.txt +45 -0
  132. data/lib/random-words/words/hipster/terminators.txt +16 -0
  133. data/lib/random-words/words/hipster/verbs-passive.txt +88 -0
  134. data/lib/random-words/words/hipster/verbs-plural.txt +106 -0
  135. data/lib/random-words/words/hipster/verbs-singular.txt +114 -0
  136. data/lib/random-words/words/latin/config.yml +4 -0
  137. data/lib/random-words/words/latin/conjunctions-coordinating.txt +15 -0
  138. data/lib/random-words/words/latin/names.txt +93 -0
  139. data/lib/random-words/words/latin/numbers.yml +5 -0
  140. data/lib/random-words/words/latin/phrases.txt +16 -0
  141. data/lib/random-words/words/latin/prepositions.txt +18 -0
  142. data/lib/random-words/words/latin/terminators.txt +16 -0
  143. data/lib/random-words/words/spanish/adjectives.txt +81 -0
  144. data/lib/random-words/words/spanish/adverbs.txt +87 -0
  145. data/lib/random-words/words/spanish/articles-plural.txt +4 -0
  146. data/lib/random-words/words/spanish/articles-singular.txt +4 -0
  147. data/lib/random-words/words/spanish/clauses.txt +74 -0
  148. data/lib/random-words/words/spanish/config.yml +4 -0
  149. data/lib/random-words/words/spanish/conjunctions-coordinating.txt +8 -0
  150. data/lib/random-words/words/spanish/conjunctions-subordinate.txt +16 -0
  151. data/lib/random-words/words/spanish/names.txt +61 -0
  152. data/lib/random-words/words/spanish/nouns-plural.txt +92 -0
  153. data/lib/random-words/words/spanish/nouns-singular.txt +125 -0
  154. data/lib/random-words/words/spanish/numbers.yml +5 -0
  155. data/lib/random-words/words/spanish/phrases.txt +31 -0
  156. data/lib/random-words/words/spanish/prepositions.txt +31 -0
  157. data/lib/random-words/words/spanish/terminators.txt +17 -0
  158. data/lib/random-words/words/spanish/verbs-passive.txt +495 -0
  159. data/lib/random-words/words/spanish/verbs-plural.txt +326 -0
  160. data/lib/random-words/words/spanish/verbs-singular.txt +351 -0
  161. data/lib/random-words/words/veggie/adjectives.txt +111 -0
  162. data/lib/random-words/words/veggie/adverbs.txt +81 -0
  163. data/lib/random-words/words/veggie/articles-plural.txt +10 -0
  164. data/lib/random-words/words/veggie/articles-singular.txt +10 -0
  165. data/lib/random-words/words/veggie/clauses.txt +57 -0
  166. data/lib/random-words/words/veggie/config.yml +4 -0
  167. data/lib/random-words/words/veggie/conjunctions-coordinating.txt +20 -0
  168. data/lib/random-words/words/veggie/conjunctions-subordinate.txt +29 -0
  169. data/lib/random-words/words/veggie/names.txt +93 -0
  170. data/lib/random-words/words/veggie/nouns-plural.txt +78 -0
  171. data/lib/random-words/words/veggie/nouns-singular.txt +105 -0
  172. data/lib/random-words/words/veggie/numbers.yml +5 -0
  173. data/lib/random-words/words/veggie/phrases.txt +20 -0
  174. data/lib/random-words/words/veggie/prepositions.txt +45 -0
  175. data/lib/random-words/words/veggie/terminators.txt +16 -0
  176. data/lib/random-words/words/veggie/verbs-passive.txt +56 -0
  177. data/lib/random-words/words/veggie/verbs-plural.txt +79 -0
  178. data/lib/random-words/words/veggie/verbs-singular.txt +79 -0
  179. data/lib/random-words.rb +28 -0
  180. data/random-words.gemspec +3 -1
  181. data/src/_README.md +208 -15
  182. metadata +181 -9
  183. data/lib/random-words/words/bacon/numbers.txt +0 -21
  184. data/lib/random-words/words/corporate/numbers.txt +0 -21
  185. data/lib/random-words/words/english/numbers.txt +0 -21
  186. 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 '../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
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: '1;30',
31
- boldred: '1;31',
32
- boldgreen: '1;32',
33
- boldyellow: '1;33',
34
- boldblue: '1;34',
35
- boldmagenta: '1;35',
36
- boldcyan: '1;36',
37
- boldwhite: '1;37',
38
- reset: 0
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('=' * text.length, :boldgreen)
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('-' * text.length, :boldyellow)
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 || 3
81
- header_1('Random Combined Sentences:')
82
- @sentence_generator.sentences(number_of_sentences).each_with_index do |_sentence, _index|
83
- puts text(sentence(:medium))
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('Random Sentences')
89
- @sentence_generator.lengths.keys.each do |length|
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('Random Paragraphs')
96
- @sentence_generator.lengths.keys.each do |length|
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 = 10
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
- s = @sentence_generator.words(number_of_words)
106
- puts "#{marker} #{text(s)} "
107
- puts counter("#{s.split(/ /).count} words, #{s.length} characters")
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('Random Characters (exact length)')
113
- [20, 50, 120, 200].each do |i|
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
- header_1('Random Characters (length range)')
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('', @colors[:marker])
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(']', @colors[:bracket])}"
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 = 'Usage: randw [options]'
165
-
166
- opts.separator 'Options:'
167
-
168
- opts.on('-S', '--source [SOURCE]', 'Specify the source language (default: latin)') do |source|
169
- @options[:source] = case source
170
- when /^e/
171
- :english
172
- when /^l/
173
- :latin
174
- when /^(co|pro)/
175
- :corporate
176
- when /^(me|ba|ca)/
177
- :bacon
178
- else
179
- :latin
180
- end
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('-l', '--length [short|medium|long|very_long]', 'Specify the length of the sentence') do |length|
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
- when /^s/
186
- :short
187
- when /^l/
188
- :long
189
- when /^v/
190
- :very_long
191
- else
192
- :medium
193
- end
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('--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|
197
236
  @options[:paragraph_length] = length.to_i
198
237
  end
199
238
 
200
- opts.on('-s', '--sentences [NUMBER]', 'Generate random sentences') do |number|
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.to_i
247
+ @options[:count] = number&.to_i || 3
203
248
  end
204
249
 
205
- opts.on('-p', '--paragraphs [NUMBER]', 'Generate random paragraphs') do |number|
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('-w', '--words [NUMBER]', 'Generate random words') do |number|
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('-c', '--characters [NUMBER]', 'Generate random characters') do |number|
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('--password', 'Generate a random password') do
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.on('--separator [CHAR]', 'Specify the separator character for the password') do |separator|
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('-n', '--no-whitespace', 'Specify whether to remove whitespace in generated text (characters only)') do
230
- @options[:whitespace] = false
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.on('-d', '--debug', 'Enable debug mode, displays sentence/word/character counts') do
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('-h', '--help', 'Display this help message') do
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('-v', '--version', 'Display the version') do
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('-t', '--test', 'Run the full debug test') do
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
- s = @rw.sentence
278
- total[:words] += s.split(/ /).count
279
- total[:characters] += s.length
280
- print s
281
- debug "#{s.split(/ /).count}w, #{s.length}c"
282
- end
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(/[oleat]/i)
477
+ m = p.match(/[oleats]/i)
312
478
  if m
313
479
  num_char = m.begin(0)
314
- char = m[0].tr('oleat', '01347')
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 ? '' : %w[! @ # $ % ^ & * ( ) _ + - = ; : < > , . ? /].sample
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 'Please specify a valid method: sentences, paragraphs, words, or characters.'
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