random-words 1.0.16 → 1.0.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b39309d58668b2ae045ea68974a6281e6256f65a3810cddb75a808d6484a372
4
- data.tar.gz: 67954ff10b5a2dd032bcbd1776444998c69eb5fb4e85bfb890477e9731ca67ed
3
+ metadata.gz: d01d64360e59eadf8e0578b1ef16d48d40a2eac57184071c45383e3133387f0e
4
+ data.tar.gz: 33b2fa7b4351254109916d6b5fb313d9e269a891481c172c417b0e333bd7db34
5
5
  SHA512:
6
- metadata.gz: c507cbb755b641f23b2249e4e989ee11fb65bcc61d628e453bdf6d7fd03f0859f064efe00c38ea848e42674b61b5c2264b51eb0b53e9875d746ec5f7bb8e37dc
7
- data.tar.gz: bf006d722b68479d26fc7be323beb6c5cfd9548c4c71a3c63a2c462968df46f2971268ba4cd5c3292f3ed20cbb461c44f99123aed21b487bc1a2c1020f4392b0
6
+ metadata.gz: 0b707d9517be318b909f9106d14e22bda99789c08918ddaa0a14214a4dded82719285e15b37c413c71d28bec4ea3cff3650f227abe6bd2c5f1110b3afc3bb4bd
7
+ data.tar.gz: 00cdb6e05557682584a0ec4e5b8ed31b9b527fe8f905fbd481b2b137622c8f3a3651d2628f8ea0bbc799f8aa98ce0dc37e635bb544df9847ae9d3feeb8cbb614
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ### 1.0.18
2
+
3
+ 2025-05-28 07:16
4
+
5
+ #### IMPROVED
6
+
7
+ - More templates for sentence structure variety
8
+
9
+ #### FIXED
10
+
11
+ - Just remove a/an from articles to avoid article disagreement
12
+ - Remove m-dash from separators as it was causing a double-space bug
13
+
14
+ ### 1.0.17
15
+
16
+ 2025-05-24 10:47
17
+
18
+ #### FIXED
19
+
20
+ - More encoding fixes
21
+
1
22
  ### 1.0.16
2
23
 
3
24
  2025-05-24 09:19
data/bin/randw CHANGED
@@ -288,7 +288,7 @@ when :sentences
288
288
  s = @rw.sentences(@options[:count]).join(" ")
289
289
  total[:words] += s.split(/ /).count
290
290
  total[:characters] += s.length
291
- print s
291
+ print s.clean_output
292
292
  debug "#{s.split(/ /).count}w, #{s.length}c"
293
293
  # end
294
294
  debug "Total: #{total[:sentences]}s, #{total[:words]}w, #{total[:characters]}c"
@@ -303,18 +303,18 @@ when :paragraphs
303
303
  total[:sentences] += p.scan(/[?.!]/).count
304
304
  total[:words] += p.split(/ /).count
305
305
  total[:characters] += p.length
306
- print p
306
+ print p.clean_output
307
307
  debug "#{p.scan(/[?.!]/).count}s, #{p.split(/ /).count}w, #{p.length}c"
308
308
  puts "\n\n"
309
309
  end
310
310
  debug "Total: #{total[:sentences]}s, #{total[:words]}w, #{total[:characters]}c"
311
311
  when :words
312
312
  w = @rw.words(@options[:count])
313
- print w
313
+ print w.clean_output
314
314
  debug "#{w.split(/ /).count}w, #{w.length}c"
315
315
  when :characters
316
316
  c = @rw.characters(@options[:count], whitespace: @options[:whitespace])
317
- print c
317
+ print c.clean_output
318
318
  debug "#{c.split(/ /).count}w, #{c.length}c"
319
319
  when :markdown, :html
320
320
  settings = markdown_settings(@options[:markdown_settings])
@@ -326,9 +326,9 @@ when :markdown, :html
326
326
  settings[:extended] = @rw.use_extended_punctuation
327
327
 
328
328
  if @options[:method] == :markdown
329
- puts @rw.markdown(settings)
329
+ puts @rw.markdown(settings).clean_output
330
330
  else
331
- puts @rw.html(settings)
331
+ puts @rw.html(settings).clean_output
332
332
  end
333
333
  when :password
334
334
  p = @rw.characters(20, whitespace: @options[:whitespace], article: false)
@@ -39,6 +39,58 @@ module RandomWords
39
39
  # These parts will be used to generate random sentences and character strings
40
40
  SENTENCE_PARTS = %w[random_article random_adjective random_noun random_adverb random_verb random_adjective
41
41
  random_verb random_adverb random_phrase].freeze
42
+ TEMPLATES = [
43
+ # Simple declarative
44
+ %i[random_article random_adjective random_noun random_verb],
45
+ %i[random_plural_article random_adjective random_plural_noun random_plural_verb],
46
+
47
+ # With adverb
48
+ %i[random_article random_adjective random_noun random_adverb random_verb],
49
+ %i[random_name random_adverb random_verb],
50
+
51
+ # Passive voice
52
+ %i[random_article random_noun random_passive_verb random_preposition random_article random_noun],
53
+
54
+ # With prepositional phrase
55
+ %i[random_article random_adjective random_noun random_verb random_preposition random_article random_noun],
56
+
57
+ # Compound sentence
58
+ %i[random_article random_noun random_verb random_coordinating_conjunction random_article random_noun random_verb],
59
+
60
+ # Subordinate clause
61
+ %i[random_clause random_article random_noun random_verb],
62
+
63
+ # With phrase
64
+ %i[random_phrase],
65
+
66
+ # Name as subject
67
+ %i[random_name random_verb random_article random_noun],
68
+
69
+ # Plural with adverb and preposition
70
+ %i[random_plural_article random_plural_noun random_adverb random_plural_verb random_preposition random_article random_noun],
71
+
72
+ # Coordinating conjunction joining two clauses
73
+ %i[random_article random_noun random_verb random_coordinating_conjunction random_plural_article random_plural_noun random_plural_verb
74
+ random_phrase],
75
+
76
+ # Subordinate conjunction
77
+ %i[random_subordinate_conjunction random_article random_noun random_verb random_article random_noun random_verb],
78
+
79
+ # With random_adjective and random_adverb in various places
80
+ %i[random_adverb random_article random_adjective random_noun random_verb],
81
+ %i[random_article random_noun random_verb random_adverb],
82
+
83
+ # Name with phrase
84
+ %i[random_name random_verb random_phrase],
85
+
86
+ # Plural passive
87
+ %i[random_plural_article random_plural_noun random_passive_verb random_preposition random_article random_noun],
88
+
89
+ # Name with subordinate clause
90
+ %i[random_name random_verb random_subordinate_conjunction random_article random_noun random_verb]
91
+ ].freeze
92
+
93
+ OPTIONAL_PARTS = %i[adjectives adverbs].freeze
42
94
 
43
95
  # Initialize the generator with a source and options
44
96
  # @param source [Symbol] The source of the words (e.g., :english)
@@ -649,13 +701,14 @@ module RandomWords
649
701
 
650
702
  # Generate a random set of separators
651
703
  def random_separators
652
- [',', ',', ',', ';', ':', ' —']
704
+ [',', ',', ',', ';', ':']
653
705
  end
654
706
 
655
707
  # Generate a random separator
656
708
  # @return [String] A randomly selected separator
657
709
  def random_separator
658
- "#{dbg('SEP')}#{random_separators.sample}"
710
+ sep = random_separators.sample
711
+ "#{dbg('SEP')}#{sep}"
659
712
  end
660
713
 
661
714
  # Generate a random subordinate conjunction
@@ -726,18 +779,16 @@ module RandomWords
726
779
  "#{random_number_with_plural} #{random_adverb} #{random_plural_verb}"
727
780
  when 4..5
728
781
  random_name
729
- when 6..7
730
- noun = random_noun
731
- "#{random_adverb}, #{random_article_for_word(noun)} #{noun} #{random_verb}"
782
+ when 6
783
+ "#{random_adverb}, #{random_article_for_word(random_noun)} #{random_noun} #{random_verb}"
732
784
  else
733
- noun = random_noun
734
- adjective = random_adjective
735
- "#{random_article_for_word(adjective)} #{adjective} #{noun} #{random_adverb} #{random_verb}"
785
+ TEMPLATES.sample.map { |part| send(part.to_sym) }.join(' ')
736
786
  end
737
787
  tail = roll(50) ? " #{random_prepositional_phrase}" : ''
738
788
  separator = random_separator
789
+
739
790
  tail += roll(10) ? "#{separator} #{random_clause}" : ''
740
- "#{beginning.strip.sub(/[#{Regexp.escape(separator)}]*$/, separator)}#{tail}"
791
+ "#{beginning.strip.sub(/([#{Regexp.escape(separator)}]|#{Regexp.escape(separator)})*$/, separator)}#{tail}"
741
792
  end
742
793
 
743
794
  # Simplified generate_additional_clauses
File without changes
@@ -124,8 +124,8 @@ module RandomWords
124
124
  items = { short: 4, medium: 8, long: 10, very_long: 12 }[@options[:length]]
125
125
 
126
126
  if @options[:ul] && @options[:ol]
127
- inject_block(1, -> { list(items, :ul) })
128
- inject_block(1, -> { list(items, :ol) })
127
+ inject_block(1, -> { list(items, :ul, rule: true) })
128
+ inject_block(1, -> { list(items, :ol, rule: true) })
129
129
  elsif @options[:ul]
130
130
  inject_block(2, -> { list(items, :ul) })
131
131
  elsif @options[:ol]
@@ -189,9 +189,10 @@ module RandomWords
189
189
  # Generates a list of items.
190
190
  # @param [Integer] count The number of items to generate.
191
191
  # @param [Symbol] type The type of list to generate (:ul, :ol, :dl).
192
+ # @param [Boolean] hr whether to add a horizontal rule after list
192
193
  #
193
194
  # @return [String] The generated list.
194
- def list(count, type)
195
+ def list(count, type, rule: false)
195
196
  ul = "\n\n<#{type}>\n"
196
197
 
197
198
  count.times do
@@ -217,7 +218,9 @@ module RandomWords
217
218
  ul += "\t<li>#{long_frag}</li>\n"
218
219
  end
219
220
  end
220
- ul + "</#{type}>\n\n"
221
+ ul += "</#{type}>\n\n"
222
+ ul += "<hr>\n\n" if rule
223
+ ul
221
224
  end
222
225
 
223
226
  # Generates a blockquote.
@@ -376,7 +379,6 @@ module RandomWords
376
379
 
377
380
  @output = "#{grafs.slice!(0, len).join("\n\n")}\n\n"
378
381
 
379
- # count = { short: 4, medium: 8, long: 10, very_long: 12 }[@options[:length]]
380
382
  @output += block.call
381
383
  added = 1
382
384
  while grafs.any?
@@ -236,6 +236,8 @@ module RandomWords
236
236
  new_source = nil
237
237
  sources = RandomWords::Generator.new.sources
238
238
 
239
+ return sources.map { |k, v| v.name }.sample if /^(random|any)$/i.match?(self)
240
+
239
241
  sources.each do |_k, v|
240
242
  v.names.each do |name|
241
243
  next unless /^#{self}/i.match?(name.to_s)
@@ -355,5 +357,9 @@ module RandomWords
355
357
  /\A[aeiou]/i.match?(word) ? "an #{word}" : "a #{word}"
356
358
  end
357
359
  end
360
+
361
+ def clean_output
362
+ encode('iso-8859-1', undef: :replace, invalid: :replace, replace: '').force_encoding('UTF-8')
363
+ end
358
364
  end
359
365
  end
@@ -1,4 +1,4 @@
1
1
  module RandomWords
2
2
  # The version of the RandomWords gem.
3
- VERSION = '1.0.16'
3
+ VERSION = '1.0.18'
4
4
  end
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
@@ -1,5 +1,3 @@
1
- a
2
- an
3
1
  the
4
2
  each
5
3
  every
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random-words
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -73,6 +73,7 @@ files:
73
73
  - lib/random-words/generator.rb
74
74
  - lib/random-words/hash.rb
75
75
  - lib/random-words/html2markdown.rb
76
+ - lib/random-words/lorem-markdown.rb
76
77
  - lib/random-words/lorem_html.rb
77
78
  - lib/random-words/number_to_word.rb
78
79
  - lib/random-words/numeric.rb