xqsr3 0.38.2 → 0.39.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -6
  3. data/examples/count_word_frequencies.md +12 -12
  4. data/examples/count_word_frequencies.rb +4 -4
  5. data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
  6. data/lib/xqsr3/array_utilities.rb +2 -2
  7. data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
  8. data/lib/xqsr3/command_line_utilities.rb +2 -2
  9. data/lib/xqsr3/containers/frequency_map.rb +399 -399
  10. data/lib/xqsr3/containers/multi_map.rb +448 -448
  11. data/lib/xqsr3/containers.rb +3 -3
  12. data/lib/xqsr3/conversion/bool_parser.rb +51 -51
  13. data/lib/xqsr3/conversion/integer_parser.rb +87 -87
  14. data/lib/xqsr3/conversion.rb +3 -3
  15. data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
  16. data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
  17. data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
  18. data/lib/xqsr3/diagnostics.rb +3 -3
  19. data/lib/xqsr3/doc_.rb +130 -130
  20. data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
  21. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
  22. data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
  23. data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
  24. data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
  25. data/lib/xqsr3/extensions/hash/except.rb +16 -16
  26. data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
  27. data/lib/xqsr3/extensions/hash/match.rb +10 -10
  28. data/lib/xqsr3/extensions/hash/slice.rb +11 -11
  29. data/lib/xqsr3/extensions/hash.rb +1 -1
  30. data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
  31. data/lib/xqsr3/extensions/integer.rb +3 -0
  32. data/lib/xqsr3/extensions/io/writelines.rb +28 -28
  33. data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
  34. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
  35. data/lib/xqsr3/extensions/kernel.rb +1 -0
  36. data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
  37. data/lib/xqsr3/extensions/string/map_option_string.rb +4 -4
  38. data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
  39. data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
  40. data/lib/xqsr3/extensions/string/quote_if.rb +1 -1
  41. data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
  42. data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
  43. data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
  44. data/lib/xqsr3/extensions/string/truncate.rb +1 -1
  45. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
  46. data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
  47. data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
  48. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
  49. data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
  50. data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
  51. data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
  52. data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
  53. data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
  54. data/lib/xqsr3/extensions.rb +5 -5
  55. data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
  56. data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
  57. data/lib/xqsr3/hash_utilities.rb +3 -3
  58. data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
  59. data/lib/xqsr3/io/writelines.rb +122 -120
  60. data/lib/xqsr3/quality/parameter_checking.rb +445 -445
  61. data/lib/xqsr3/quality.rb +2 -2
  62. data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
  63. data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
  64. data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
  65. data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
  66. data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
  67. data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
  68. data/lib/xqsr3/string_utilities/truncate.rb +55 -55
  69. data/lib/xqsr3/string_utilities.rb +8 -8
  70. data/lib/xqsr3/version.rb +12 -12
  71. data/test/performance/frequency_map.rb +12 -12
  72. data/test/scratch/test_assert_raise_with_message.rb +11 -11
  73. data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
  74. data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
  75. data/test/unit/containers/tc_frequency_map.rb +591 -591
  76. data/test/unit/containers/tc_multi_map.rb +558 -558
  77. data/test/unit/conversion/tc_integer_parser.rb +72 -72
  78. data/test/unit/conversion/tc_to_bool.rb +25 -25
  79. data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
  80. data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
  81. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
  82. data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
  83. data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
  84. data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
  85. data/test/unit/extensions/hash/tc_except.rb +28 -28
  86. data/test/unit/extensions/hash/tc_slice.rb +13 -13
  87. data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
  88. data/test/unit/extensions/integer/ts_all.rb +12 -0
  89. data/test/unit/extensions/io/tc_writelines.rb +149 -77
  90. data/test/unit/extensions/kernel/tc_integer.rb +75 -75
  91. data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
  92. data/test/unit/extensions/object/tc_inspect.rb +50 -50
  93. data/test/unit/extensions/string/tc_bool.tb +24 -24
  94. data/test/unit/extensions/string/tc_ends_with.rb +53 -53
  95. data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
  96. data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
  97. data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
  98. data/test/unit/extensions/string/tc_quote_if.rb +18 -18
  99. data/test/unit/extensions/string/tc_starts_with.rb +53 -53
  100. data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
  101. data/test/unit/extensions/string/tc_truncate.rb +18 -18
  102. data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
  103. data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
  104. data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
  105. data/test/unit/hash_utilities/tc_has_match.rb +70 -70
  106. data/test/unit/hash_utilities/tc_match.rb +83 -83
  107. data/test/unit/io/tc_writelines.rb +166 -106
  108. data/test/unit/quality/tc_parameter_checking.rb +389 -389
  109. data/test/unit/string_utilities/tc_truncate.rb +27 -27
  110. data/test/unit/tc_version.rb +15 -15
  111. metadata +6 -2
@@ -5,13 +5,13 @@
5
5
  # Purpose: Adds a writelines() method to the IO module
6
6
  #
7
7
  # Created: 13th April 2007
8
- # Updated: 11th December 2023
8
+ # Updated: 12th April 2024
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2019-2023, Matthew Wilson and Synesis Information Systems
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
15
15
  # Copyright (c) 2007-2019, Matthew Wilson and Synesis Software
16
16
  # All rights reserved.
17
17
  #
@@ -56,174 +56,176 @@ require 'xqsr3/quality/parameter_checking'
56
56
  module Xqsr3
57
57
  module IO
58
58
 
59
- private
60
- # @!visibility private
61
- module WriteLine_Constants_ #:nodoc: all
59
+ private
60
+ # @!visibility private
61
+ module WriteLine_Constants_ #:nodoc: all
62
62
 
63
- NUMBER_OF_LINES_TO_EXAMINE = 20
64
- end # module WriteLine_Constants_
63
+ NUMBER_OF_LINES_TO_EXAMINE = 20
64
+ end # module WriteLine_Constants_
65
65
 
66
- private
66
+ private
67
67
 
68
- # @!visibility private
69
- def self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol # :nodoc:
68
+ # @!visibility private
69
+ def self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol # :nodoc:
70
70
 
71
- $stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}', contents(#{contents.class})='#{contents}', line_separator(#{line_separator.class})='#{line_separator}', column_separator(#{column_separator.class})='#{column_separator}', no_last_eol(#{no_last_eol.class})=#{no_last_eol})" if $DEBUG
71
+ =begin
72
+ $stderr.puts "#{self.class}.write_to_target_(target(#{target.class})='#{target}', contents(#{contents.class})='#{contents}', line_separator(#{line_separator.class})='#{line_separator}', column_separator(#{column_separator.class})='#{column_separator}', no_last_eol(#{no_last_eol.class})=#{no_last_eol})" if $DEBUG
73
+ =end
72
74
 
73
- if no_last_eol
75
+ if no_last_eol
74
76
 
75
- first = true
77
+ first = true
76
78
 
77
- if contents.instance_of? ::Hash
79
+ if contents.instance_of? ::Hash
78
80
 
79
- contents.each do |k, v|
81
+ contents.each do |k, v|
80
82
 
81
- target << line_separator unless first
83
+ target << line_separator unless first
82
84
 
83
- target << "#{k}#{column_separator}#{v}"
85
+ target << "#{k}#{column_separator}#{v}"
84
86
 
85
- first = false
86
- end
87
- else
87
+ first = false
88
+ end
89
+ else
88
90
 
89
- contents.each do |element|
91
+ contents.each do |element|
90
92
 
91
- target << line_separator unless first
93
+ target << line_separator unless first
92
94
 
93
- target << "#{element}"
95
+ target << "#{element}"
94
96
 
95
- first = false
96
- end
97
- end
98
- else
97
+ first = false
98
+ end
99
+ end
100
+ else
99
101
 
100
- if contents.instance_of? ::Hash
102
+ if contents.instance_of? ::Hash
101
103
 
102
- contents.each do |k, v|
104
+ contents.each do |k, v|
103
105
 
104
- target << "#{k}#{column_separator}#{v}#{line_separator}"
105
- end
106
- else
106
+ target << "#{k}#{column_separator}#{v}#{line_separator}"
107
+ end
108
+ else
107
109
 
108
- contents.each do |element|
110
+ contents.each do |element|
109
111
 
110
- target << "#{element}#{line_separator}"
111
- end
112
- end
113
- end
112
+ target << "#{element}#{line_separator}"
113
+ end
114
+ end
115
+ end
114
116
 
115
- contents.size
116
- end
117
+ contents.size
118
+ end
117
119
 
118
- # This function checks to see if any part of the entries contains an
119
- # embedded eol, in which case the empty string is returned to force no
120
- # (additional) separator will be used. Otherwise, it returns "\n" to
121
- # ensure that that is used.
122
- #
123
- # @!visibility private
124
- def self.deduce_line_separator_ contents, eol_lookahead_limit # :nodoc:
120
+ # This function checks to see if any part of the entries contains an
121
+ # embedded eol, in which case the empty string is returned to force no
122
+ # (additional) separator will be used. Otherwise, it returns "\n" to
123
+ # ensure that that is used.
124
+ #
125
+ # @!visibility private
126
+ def self.deduce_line_separator_ contents, eol_lookahead_limit # :nodoc:
125
127
 
126
- if contents.instance_of? ::Hash
128
+ if contents.instance_of? ::Hash
127
129
 
128
- contents.each_with_index do |k, v, index|
130
+ contents.each_with_index do |k, v, index|
129
131
 
130
- if eol_lookahead_limit && eol_lookahead_limit == index
132
+ if eol_lookahead_limit && eol_lookahead_limit == index
131
133
 
132
- break
133
- else
134
+ break
135
+ else
134
136
 
135
- return '' if v.to_s.include? "\n"
136
- return '' if k.to_s.include? "\n"
137
- end
138
- end
139
- else
137
+ return '' if v.to_s.include? "\n"
138
+ return '' if k.to_s.include? "\n"
139
+ end
140
+ end
141
+ else
140
142
 
141
- contents.each_with_index do |element, index|
143
+ contents.each_with_index do |element, index|
142
144
 
143
- if eol_lookahead_limit && eol_lookahead_limit == index
145
+ if eol_lookahead_limit && eol_lookahead_limit == index
144
146
 
145
- break
146
- else
147
+ break
148
+ else
147
149
 
148
- return '' if element.to_s.include? "\n"
149
- end
150
- end
151
- end
150
+ return '' if element.to_s.include? "\n"
151
+ end
152
+ end
153
+ end
152
154
 
153
- "\n"
154
- end
155
+ "\n"
156
+ end
155
157
 
156
- public
158
+ public
157
159
 
158
- # Writes the contents to the target, subject to the options
159
- #
160
- # === Signature
161
- #
162
- # * *Parameters:*
163
- # - +target+ The target of the write, which may be a string containing the path or a stream instance that supports write
164
- # - +contents+ The contents to be write, which may be a +Hash+, or an +Array+, or a +String+ containing delimited fields
165
- # - +options+ An options hash, containing any of the following options
166
- #
167
- # * *Options:*
168
- # - +:column_separator+ {optional} The column separator, to be applied between each field in the case where +contents+ is a +Hash+.
169
- # - +:eol_lookahead_limit+ {optional} The number of content elements (line/pair) to inspect to determine whether element has a terminating end-of-line sequence. Defaults to 20. If 0, and +:line_separator+ is not specified, then will default to <tt>"\n"</tt>. If +nil+, then every line will be inspected.
170
- # - +:line_separator+ {optional} The line separator, to be applied to the end of line created from each entry. When not specified, it will be deduced by inspecting +contents+ (according to +eol_lookahead_limit+).
171
- # - +:no_last_eol+ {optional} If present and _truey_, causes suppression of the addition of the +:line_separator+ on the last line.
172
- #
173
- # === Return
174
- #
175
- # The number of entries in +contents+
176
- def self.writelines target, contents, options = {}
160
+ # Writes the contents to the target, subject to the options
161
+ #
162
+ # === Signature
163
+ #
164
+ # * *Parameters:*
165
+ # - +target+ The target of the write, which may be a string containing the path or a stream instance that supports write
166
+ # - +contents+ The contents to be write, which may be a +Hash+, or an +Array+, or a +String+ containing delimited fields
167
+ # - +options+ An options hash, containing any of the following options
168
+ #
169
+ # * *Options:*
170
+ # - +:column_separator+ {optional} The column separator, to be applied between each field in the case where +contents+ is a +Hash+.
171
+ # - +:eol_lookahead_limit+ {optional} The number of content elements (line/pair) to inspect to determine whether element has a terminating end-of-line sequence. Defaults to 20. If 0, and +:line_separator+ is not specified, then will default to <tt>"\n"</tt>. If +nil+, then every line will be inspected.
172
+ # - +:line_separator+ {optional} The line separator, to be applied to the end of line created from each entry. When not specified, it will be deduced by inspecting +contents+ (according to +eol_lookahead_limit+).
173
+ # - +:no_last_eol+ {optional} If present and _truey_, causes suppression of the addition of the +:line_separator+ on the last line.
174
+ #
175
+ # === Return
176
+ #
177
+ # The number of entries in +contents+
178
+ def self.writelines target, contents, options = {}
177
179
 
178
- # validate parameters
180
+ # validate parameters
179
181
 
180
- ::Xqsr3::Quality::ParameterChecking.check_parameter(target, 'target', allow_nil: false) do |v|
182
+ ::Xqsr3::Quality::ParameterChecking.check_parameter(target, 'target', allow_nil: false) do |v|
181
183
 
182
- raise TypeError, "#{self}#writeline() 'target' parameter must be a #{::String} or respond to <<" unless ::String === v || v.respond_to?(:<<)
183
- true
184
- end
185
- ::Xqsr3::Quality::ParameterChecking.check_parameter(contents, 'contents', allow_nil: false, types: [ ::String, ::Hash, ::Array ])
184
+ raise TypeError, "#{self}#writeline() 'target' parameter must be a #{::String} or respond to <<" unless ::String === v || v.respond_to?(:<<)
185
+ true
186
+ end
187
+ ::Xqsr3::Quality::ParameterChecking.check_parameter(contents, 'contents', allow_nil: false, types: [ ::String, ::Hash, ::Array ])
186
188
 
187
- # process parameters
189
+ # process parameters
188
190
 
189
- if contents.instance_of? String
191
+ if contents.instance_of? String
190
192
 
191
- if contents.include? "\n"
193
+ if contents.include? "\n"
192
194
 
193
- contents = contents.split(/\r?\n/, -1)
194
- else
195
+ contents = contents.split(/\r?\n/, -1)
196
+ else
195
197
 
196
- contents = [ contents ]
197
- end
198
- end
198
+ contents = [ contents ]
199
+ end
200
+ end
199
201
 
200
- options ||= {}
201
- eol_lookahead_limit = options[:eol_lookahead_limit] || WriteLine_Constants_::NUMBER_OF_LINES_TO_EXAMINE
202
- column_separator = options[:column_separator] || ''
203
- no_last_eol = options[:no_last_eol] || false
204
- line_separator = nil
205
- line_separator ||= options[:line_separator]
206
- line_separator ||= self.deduce_line_separator_(contents, eol_lookahead_limit) unless !eol_lookahead_limit.kind_of?(::Integer) || 0 == eol_lookahead_limit
207
- line_separator ||= "\n"
202
+ options ||= {}
203
+ eol_lookahead_limit = options[:eol_lookahead_limit] || WriteLine_Constants_::NUMBER_OF_LINES_TO_EXAMINE
204
+ column_separator = options[:column_separator] || ''
205
+ no_last_eol = options[:no_last_eol] || false
206
+ line_separator = nil
207
+ line_separator ||= options[:line_separator]
208
+ line_separator ||= self.deduce_line_separator_(contents, eol_lookahead_limit) unless !eol_lookahead_limit.kind_of?(::Integer) || 0 == eol_lookahead_limit
209
+ line_separator ||= "\n"
208
210
 
209
- if not contents.kind_of? ::Enumerable and not contents.instance_of? ::Hash
211
+ if not contents.kind_of? ::Enumerable and not contents.instance_of? ::Hash
210
212
 
211
- raise ArgumentError, "writelines() must be passed a #{::String}, or a #{::Hash}, or an #{::Enumerable} (or derived)"
212
- end
213
+ raise ArgumentError, "writelines() must be passed a #{::String}, or a #{::Hash}, or an #{::Enumerable} (or derived)"
214
+ end
213
215
 
214
- # do the writing
216
+ # do the writing
215
217
 
216
- if ::String === target
218
+ if ::String === target
217
219
 
218
- File.open(target, "w") do |io|
220
+ File.open(target, "w") do |io|
219
221
 
220
- self.write_to_target_ io, contents, line_separator, column_separator, no_last_eol
221
- end
222
- else
222
+ self.write_to_target_ io, contents, line_separator, column_separator, no_last_eol
223
+ end
224
+ else
223
225
 
224
- self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol
225
- end
226
- end # writelines
226
+ self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol
227
+ end
228
+ end # writelines
227
229
  end # module IO
228
230
  end # module Xqsr3
229
231