xqsr3 0.38.1.1 → 0.39.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -6
  3. data/examples/count_word_frequencies.md +13 -13
  4. data/examples/count_word_frequencies.rb +5 -5
  5. data/lib/xqsr3/array_utilities/join_with_or.rb +53 -54
  6. data/lib/xqsr3/array_utilities.rb +2 -2
  7. data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -67
  8. data/lib/xqsr3/command_line_utilities.rb +2 -2
  9. data/lib/xqsr3/containers/frequency_map.rb +405 -404
  10. data/lib/xqsr3/containers/multi_map.rb +454 -453
  11. data/lib/xqsr3/containers.rb +3 -3
  12. data/lib/xqsr3/conversion/bool_parser.rb +56 -57
  13. data/lib/xqsr3/conversion/integer_parser.rb +92 -93
  14. data/lib/xqsr3/conversion.rb +3 -3
  15. data/lib/xqsr3/diagnostics/exception_utilities.rb +152 -151
  16. data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +99 -95
  17. data/lib/xqsr3/diagnostics/inspect_builder.rb +86 -86
  18. data/lib/xqsr3/diagnostics.rb +3 -3
  19. data/lib/xqsr3/doc_.rb +136 -136
  20. data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
  21. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +18 -17
  22. data/lib/xqsr3/extensions/enumerable/detect_map.rb +41 -41
  23. data/lib/xqsr3/extensions/enumerable/unique.rb +32 -31
  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 +34 -34
  33. data/lib/xqsr3/extensions/kernel/integer.rb +26 -26
  34. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +15 -14
  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 -5
  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 -2
  41. data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
  42. data/lib/xqsr3/extensions/string/to_bool.rb +8 -9
  43. data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
  44. data/lib/xqsr3/extensions/string/truncate.rb +1 -2
  45. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +7 -7
  46. data/lib/xqsr3/extensions/test/unit/assert_false.rb +6 -7
  47. data/lib/xqsr3/extensions/test/unit/assert_not.rb +6 -7
  48. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +7 -7
  49. data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -62
  50. data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +7 -8
  51. data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +7 -8
  52. data/lib/xqsr3/extensions/test/unit/assert_true.rb +6 -7
  53. data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -38
  54. data/lib/xqsr3/extensions.rb +5 -5
  55. data/lib/xqsr3/hash_utilities/deep_transform.rb +71 -71
  56. data/lib/xqsr3/hash_utilities/key_matching.rb +82 -82
  57. data/lib/xqsr3/hash_utilities.rb +3 -3
  58. data/lib/xqsr3/internal_/test_unit_version_.rb +130 -88
  59. data/lib/xqsr3/io/writelines.rb +125 -125
  60. data/lib/xqsr3/quality/parameter_checking.rb +452 -453
  61. data/lib/xqsr3/quality.rb +2 -2
  62. data/lib/xqsr3/string_utilities/ends_with.rb +64 -64
  63. data/lib/xqsr3/string_utilities/nil_if_empty.rb +33 -34
  64. data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +35 -35
  65. data/lib/xqsr3/string_utilities/quote_if.rb +55 -56
  66. data/lib/xqsr3/string_utilities/starts_with.rb +64 -64
  67. data/lib/xqsr3/string_utilities/to_symbol.rb +80 -80
  68. data/lib/xqsr3/string_utilities/truncate.rb +60 -61
  69. data/lib/xqsr3/string_utilities.rb +8 -8
  70. data/lib/xqsr3/version.rb +19 -20
  71. data/test/performance/frequency_map.rb +13 -27
  72. data/test/scratch/test_assert_raise_with_message.rb +12 -13
  73. data/test/unit/array_utilities/tc_join_with_or.rb +140 -142
  74. data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
  75. data/test/unit/containers/tc_frequency_map.rb +607 -554
  76. data/test/unit/containers/tc_multi_map.rb +573 -522
  77. data/test/unit/conversion/tc_integer_parser.rb +73 -73
  78. data/test/unit/conversion/tc_to_bool.rb +26 -26
  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_hash.rb +1 -1
  87. data/test/unit/extensions/hash/tc_slice.rb +14 -14
  88. data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
  89. data/test/unit/extensions/integer/ts_all.rb +12 -0
  90. data/test/unit/extensions/io/tc_writelines.rb +77 -77
  91. data/test/unit/extensions/kernel/tc_integer.rb +75 -75
  92. data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
  93. data/test/unit/extensions/object/tc_inspect.rb +51 -51
  94. data/test/unit/extensions/string/tc_bool.tb +24 -24
  95. data/test/unit/extensions/string/tc_ends_with.rb +53 -53
  96. data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
  97. data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
  98. data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
  99. data/test/unit/extensions/string/tc_quote_if.rb +18 -18
  100. data/test/unit/extensions/string/tc_starts_with.rb +53 -53
  101. data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
  102. data/test/unit/extensions/string/tc_truncate.rb +18 -18
  103. data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
  104. data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
  105. data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
  106. data/test/unit/hash_utilities/tc_has_match.rb +70 -70
  107. data/test/unit/hash_utilities/tc_match.rb +83 -83
  108. data/test/unit/io/tc_writelines.rb +106 -108
  109. data/test/unit/quality/tc_parameter_checking.rb +390 -390
  110. data/test/unit/string_utilities/tc_truncate.rb +28 -28
  111. data/test/unit/tc_version.rb +15 -15
  112. metadata +6 -2
@@ -1,133 +1,176 @@
1
1
 
2
- # provides reliable mechanism for checking the version of the
3
- # Test::Unit module
2
+ # ######################################################################## #
3
+ # File: lib/xqsr3/internal_/test_unit_version_.rb
4
+ #
5
+ # Purpose: Provides reliable mechanism for checking the version of the
6
+ # Test::Unit module
7
+ #
8
+ # Created: March 2nd 2019
9
+ # Updated: 11th December 2023
10
+ #
11
+ # Home: http://github.com/synesissoftware/xqsr3
12
+ #
13
+ # Author: Matthew Wilson
14
+ #
15
+ # Copyright (c) 2019-2023, Matthew Wilson and Synesis Information Systems
16
+ # All rights reserved.
17
+ #
18
+ # Redistribution and use in source and binary forms, with or without
19
+ # modification, are permitted provided that the following conditions are
20
+ # met:
21
+ #
22
+ # * Redistributions of source code must retain the above copyright notice,
23
+ # this list of conditions and the following disclaimer.
24
+ #
25
+ # * Redistributions in binary form must reproduce the above copyright
26
+ # notice, this list of conditions and the following disclaimer in the
27
+ # documentation and/or other materials provided with the distribution.
28
+ #
29
+ # * Neither the name of the copyright holder nor the names of its
30
+ # contributors may be used to endorse or promote products derived from
31
+ # this software without specific prior written permission.
32
+ #
33
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
35
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
37
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
+ #
45
+ # ######################################################################## #
46
+
4
47
 
5
48
  require 'test/unit'
6
49
 
7
50
  begin
8
51
 
9
- require 'test/unit/version'
52
+ require 'test/unit/version'
10
53
 
11
- # :stopdoc:
12
- # @!visibility private
13
- module Xqsr3
14
- # @!visibility private
15
- module Internal_ # :nodoc:
16
- # @!visibility private
17
- module TestUnitVersion_ # :nodoc:
54
+ # :stopdoc:
55
+ # @!visibility private
56
+ module Xqsr3
57
+ # @!visibility private
58
+ module Internal_ # :nodoc:
59
+ # @!visibility private
60
+ module TestUnitVersion_ # :nodoc:
18
61
 
19
- # @!visibility private
20
- TEST_UNIT_VERSION_ = Test::Unit::VERSION # :nodoc:
21
- end # module TestUnitVersion_
22
- end # module Internal_
23
- end # module Xqsr3
62
+ # @!visibility private
63
+ TEST_UNIT_VERSION_ = Test::Unit::VERSION # :nodoc:
64
+ end # module TestUnitVersion_
65
+ end # module Internal_
66
+ end # module Xqsr3
24
67
 
25
- # :startdoc:
26
- rescue LoadError
68
+ # :startdoc:
69
+ rescue LoadError
27
70
 
28
- # :stopdoc:
29
- # @!visibility private
30
- module Xqsr3
31
- # @!visibility private
32
- module Internal_ # :nodoc:
33
- # @!visibility private
34
- module TestUnitVersion_ # :nodoc:
71
+ # :stopdoc:
72
+ # @!visibility private
73
+ module Xqsr3
74
+ # @!visibility private
75
+ module Internal_ # :nodoc:
76
+ # @!visibility private
77
+ module TestUnitVersion_ # :nodoc:
35
78
 
36
- # @!visibility private
37
- TEST_UNIT_VERSION_ = :not_found # :nodoc:
38
- end # module TestUnitVersion_
39
- end # module Internal_
40
- end # module Xqsr3
79
+ # @!visibility private
80
+ TEST_UNIT_VERSION_ = :not_found # :nodoc:
81
+ end # module TestUnitVersion_
82
+ end # module Internal_
83
+ end # module Xqsr3
41
84
 
42
- # :startdoc:
43
- end
85
+ # :startdoc:
86
+ end
44
87
 
45
- # :stopdoc:
88
+ # :stopdoc:
46
89
 
47
- module Xqsr3
48
- module Internal_ # :nodoc:
49
- module TestUnitVersion_ # :nodoc:
90
+ module Xqsr3
91
+ module Internal_ # :nodoc:
92
+ module TestUnitVersion_ # :nodoc:
50
93
 
51
- if TEST_UNIT_VERSION_ == :not_found
94
+ if TEST_UNIT_VERSION_ == :not_found
52
95
 
53
- TEST_UNIT_VERSION_PARTS_ = []
96
+ TEST_UNIT_VERSION_PARTS_ = []
54
97
 
55
- TEST_UNIT_VERSION_MAJOR_ = nil # :nodoc:
56
- TEST_UNIT_VERSION_MINOR_ = nil # :nodoc:
57
- TEST_UNIT_VERSION_PATCH_ = nil # :nodoc:
58
- else
98
+ TEST_UNIT_VERSION_MAJOR_ = nil # :nodoc:
99
+ TEST_UNIT_VERSION_MINOR_ = nil # :nodoc:
100
+ TEST_UNIT_VERSION_PATCH_ = nil # :nodoc:
101
+ else
59
102
 
60
- TEST_UNIT_VERSION_PARTS_ = TEST_UNIT_VERSION_.split(/[.]/).collect { |n| n.to_i } # :nodoc:
103
+ TEST_UNIT_VERSION_PARTS_ = TEST_UNIT_VERSION_.split(/[.]/).collect { |n| n.to_i } # :nodoc:
61
104
 
62
- TEST_UNIT_VERSION_MAJOR_ = TEST_UNIT_VERSION_PARTS_[0] # :nodoc:
63
- TEST_UNIT_VERSION_MINOR_ = TEST_UNIT_VERSION_PARTS_[1] # :nodoc:
64
- TEST_UNIT_VERSION_PATCH_ = TEST_UNIT_VERSION_PARTS_[2] # :nodoc:
65
- end
105
+ TEST_UNIT_VERSION_MAJOR_ = TEST_UNIT_VERSION_PARTS_[0] # :nodoc:
106
+ TEST_UNIT_VERSION_MINOR_ = TEST_UNIT_VERSION_PARTS_[1] # :nodoc:
107
+ TEST_UNIT_VERSION_PATCH_ = TEST_UNIT_VERSION_PARTS_[2] # :nodoc:
108
+ end
66
109
 
67
- # @!visibility private
68
- def self.less_ a1, a2 # :nodoc:
110
+ # @!visibility private
111
+ def self.less_ a1, a2 # :nodoc:
69
112
 
70
- n_common = a1.size < a2.size ? a1.size : a2.size
113
+ n_common = a1.size < a2.size ? a1.size : a2.size
71
114
 
72
- (0...n_common).each do |ix|
115
+ (0...n_common).each do |ix|
73
116
 
74
- v1 = a1[ix]
75
- v2 = a2[ix]
117
+ v1 = a1[ix]
118
+ v2 = a2[ix]
76
119
 
77
- if v1 == v2
120
+ if v1 == v2
78
121
 
79
- next
80
- end
122
+ next
123
+ end
81
124
 
82
- if v1 < v2
125
+ if v1 < v2
83
126
 
84
- return true
85
- else
127
+ return true
128
+ else
86
129
 
87
- return false
88
- end
89
- end
130
+ return false
131
+ end
132
+ end
90
133
 
91
- if n_common != a2.size
134
+ if n_common != a2.size
92
135
 
93
- return true
94
- else
136
+ return true
137
+ else
95
138
 
96
- return false
97
- end
98
- end
139
+ return false
140
+ end
141
+ end
99
142
 
100
- # @!visibility private
101
- def self.is_major_at_least? j # :nodoc:
143
+ # @!visibility private
144
+ def self.is_major_at_least? j # :nodoc:
102
145
 
103
- return unless TEST_UNIT_VERSION_MAJOR_
146
+ return unless TEST_UNIT_VERSION_MAJOR_
104
147
 
105
- return j >= TEST_UNIT_VERSION_MAJOR_
106
- end
148
+ return j >= TEST_UNIT_VERSION_MAJOR_
149
+ end
107
150
 
108
- # @!visibility private
109
- def self.is_minor_at_least? n # :nodoc:
151
+ # @!visibility private
152
+ def self.is_minor_at_least? n # :nodoc:
110
153
 
111
- return unless TEST_UNIT_VERSION_MINOR_
154
+ return unless TEST_UNIT_VERSION_MINOR_
112
155
 
113
- return n >= TEST_UNIT_VERSION_MINOR_
114
- end
156
+ return n >= TEST_UNIT_VERSION_MINOR_
157
+ end
115
158
 
116
- # @!visibility private
117
- def self.is_at_least? v # :nodoc:
159
+ # @!visibility private
160
+ def self.is_at_least? v # :nodoc:
118
161
 
119
- v = v.split(/\./).collect { |n| n.to_i } if String === v
162
+ v = v.split(/\./).collect { |n| n.to_i } if String === v
120
163
 
121
- return !less_(TEST_UNIT_VERSION_PARTS_, v)
122
- end
164
+ return !less_(TEST_UNIT_VERSION_PARTS_, v)
165
+ end
123
166
 
124
- # @!visibility private
125
- def self.is_less? v # :nodoc:
167
+ # @!visibility private
168
+ def self.is_less? v # :nodoc:
126
169
 
127
- v = v.split(/\./).collect { |n| n.to_i } if String === v
170
+ v = v.split(/\./).collect { |n| n.to_i } if String === v
128
171
 
129
- return less_(TEST_UNIT_VERSION_PARTS_, v)
130
- end
172
+ return less_(TEST_UNIT_VERSION_PARTS_, v)
173
+ end
131
174
 
132
175
  end # module TestUnitVersion_
133
176
  end # module Internal_
@@ -137,4 +180,3 @@ end # module Xqsr3
137
180
 
138
181
  # ############################## end of file ############################# #
139
182
 
140
-
@@ -1,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: lib/xqsr3/io/writelines.rb
3
+ # File: lib/xqsr3/io/writelines.rb
4
4
  #
5
- # Purpose: Adds a writelines() method to the IO module
5
+ # Purpose: Adds a writelines() method to the IO module
6
6
  #
7
- # Created: 13th April 2007
8
- # Updated: 31st October 2019
7
+ # Created: 13th April 2007
8
+ # Updated: 29th March 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/xqsr3
10
+ # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2007-2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -25,7 +26,7 @@
25
26
  # notice, this list of conditions and the following disclaimer in the
26
27
  # documentation and/or other materials provided with the distribution.
27
28
  #
28
- # * Neither the names of the copyright holder nor the names of its
29
+ # * Neither the names of the copyright holders nor the names of its
29
30
  # contributors may be used to endorse or promote products derived from
30
31
  # this software without specific prior written permission.
31
32
  #
@@ -55,177 +56,176 @@ require 'xqsr3/quality/parameter_checking'
55
56
  module Xqsr3
56
57
  module IO
57
58
 
58
- private
59
- # @!visibility private
60
- module WriteLine_Constants_ #:nodoc: all
59
+ private
60
+ # @!visibility private
61
+ module WriteLine_Constants_ #:nodoc: all
61
62
 
62
- NUMBER_OF_LINES_TO_EXAMINE = 20
63
- end # module WriteLine_Constants_
63
+ NUMBER_OF_LINES_TO_EXAMINE = 20
64
+ end # module WriteLine_Constants_
64
65
 
65
- private
66
+ private
66
67
 
67
- # @!visibility private
68
- 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:
69
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
72
 
72
- if no_last_eol
73
+ if no_last_eol
73
74
 
74
- first = true
75
+ first = true
75
76
 
76
- if contents.instance_of? ::Hash
77
+ if contents.instance_of? ::Hash
77
78
 
78
- contents.each do |k, v|
79
+ contents.each do |k, v|
79
80
 
80
- target << line_separator unless first
81
+ target << line_separator unless first
81
82
 
82
- target << "#{k}#{column_separator}#{v}"
83
+ target << "#{k}#{column_separator}#{v}"
83
84
 
84
- first = false
85
- end
86
- else
85
+ first = false
86
+ end
87
+ else
87
88
 
88
- contents.each do |element|
89
+ contents.each do |element|
89
90
 
90
- target << line_separator unless first
91
+ target << line_separator unless first
91
92
 
92
- target << "#{element}"
93
+ target << "#{element}"
93
94
 
94
- first = false
95
- end
96
- end
97
- else
95
+ first = false
96
+ end
97
+ end
98
+ else
98
99
 
99
- if contents.instance_of? ::Hash
100
+ if contents.instance_of? ::Hash
100
101
 
101
- contents.each do |k, v|
102
+ contents.each do |k, v|
102
103
 
103
- target << "#{k}#{column_separator}#{v}#{line_separator}"
104
- end
105
- else
104
+ target << "#{k}#{column_separator}#{v}#{line_separator}"
105
+ end
106
+ else
106
107
 
107
- contents.each do |element|
108
+ contents.each do |element|
108
109
 
109
- target << "#{element}#{line_separator}"
110
- end
111
- end
112
- end
110
+ target << "#{element}#{line_separator}"
111
+ end
112
+ end
113
+ end
113
114
 
114
- contents.size
115
- end
115
+ contents.size
116
+ end
116
117
 
117
- # This function checks to see if any part of the entries contains an
118
- # embedded eol, in which case the empty string is returned to force no
119
- # (additional) separator will be used. Otherwise, it returns "\n" to
120
- # ensure that that is used.
121
- #
122
- # @!visibility private
123
- def self.deduce_line_separator_ contents, eol_lookahead_limit # :nodoc:
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:
124
125
 
125
- if contents.instance_of? ::Hash
126
+ if contents.instance_of? ::Hash
126
127
 
127
- contents.each_with_index do |k, v, index|
128
+ contents.each_with_index do |k, v, index|
128
129
 
129
- if eol_lookahead_limit && eol_lookahead_limit == index
130
+ if eol_lookahead_limit && eol_lookahead_limit == index
130
131
 
131
- break
132
- else
132
+ break
133
+ else
133
134
 
134
- return '' if v.to_s.include? "\n"
135
- return '' if k.to_s.include? "\n"
136
- end
137
- end
138
- else
135
+ return '' if v.to_s.include? "\n"
136
+ return '' if k.to_s.include? "\n"
137
+ end
138
+ end
139
+ else
139
140
 
140
- contents.each_with_index do |element, index|
141
+ contents.each_with_index do |element, index|
141
142
 
142
- if eol_lookahead_limit && eol_lookahead_limit == index
143
+ if eol_lookahead_limit && eol_lookahead_limit == index
143
144
 
144
- break
145
- else
145
+ break
146
+ else
146
147
 
147
- return '' if element.to_s.include? "\n"
148
- end
149
- end
150
- end
148
+ return '' if element.to_s.include? "\n"
149
+ end
150
+ end
151
+ end
151
152
 
152
- "\n"
153
- end
153
+ "\n"
154
+ end
154
155
 
155
- public
156
+ public
156
157
 
157
- # Writes the contents to the target, subject to the options
158
- #
159
- # === Signature
160
- #
161
- # * *Parameters:*
162
- # - +target+ The target of the write, which may be a string containing the path or a stream instance that supports write
163
- # - +contents+ The contents to be write, which may be a +Hash+, or an +Array+, or a +String+ containing delimited fields
164
- # - +options+ An options hash, containing any of the following options
165
- #
166
- # * *Options:*
167
- # - +:column_separator+ {optional} The column separator, to be applied between each field in the case where +contents+ is a +Hash+.
168
- # - +: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.
169
- # - +: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+).
170
- # - +:no_last_eol+ {optional} If present and _truey_, causes suppression of the addition of the +:line_separator+ on the last line.
171
- #
172
- # === Return
173
- #
174
- # The number of entries in +contents+
175
- def self.writelines target, contents, options = {}
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 = {}
176
177
 
177
- # validate parameters
178
+ # validate parameters
178
179
 
179
- ::Xqsr3::Quality::ParameterChecking.check_parameter(target, 'target', allow_nil: false) do |v|
180
+ ::Xqsr3::Quality::ParameterChecking.check_parameter(target, 'target', allow_nil: false) do |v|
180
181
 
181
- raise TypeError, "#{self}#writeline() 'target' parameter must be a #{::String} or respond to <<" unless ::String === v || v.respond_to?(:<<)
182
- true
183
- end
184
- ::Xqsr3::Quality::ParameterChecking.check_parameter(contents, 'contents', allow_nil: false, types: [ ::String, ::Hash, ::Array ])
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 ])
185
186
 
186
- # process parameters
187
+ # process parameters
187
188
 
188
- if contents.instance_of? String
189
+ if contents.instance_of? String
189
190
 
190
- if contents.include? "\n"
191
+ if contents.include? "\n"
191
192
 
192
- contents = contents.split(/\r?\n/, -1)
193
- else
193
+ contents = contents.split(/\r?\n/, -1)
194
+ else
194
195
 
195
- contents = [ contents ]
196
- end
197
- end
196
+ contents = [ contents ]
197
+ end
198
+ end
198
199
 
199
- options ||= {}
200
- eol_lookahead_limit = options[:eol_lookahead_limit] || WriteLine_Constants_::NUMBER_OF_LINES_TO_EXAMINE
201
- column_separator = options[:column_separator] || ''
202
- no_last_eol = options[:no_last_eol] || false
203
- line_separator = nil
204
- line_separator ||= options[:line_separator]
205
- line_separator ||= self.deduce_line_separator_(contents, eol_lookahead_limit) unless !eol_lookahead_limit.kind_of?(::Integer) || 0 == eol_lookahead_limit
206
- line_separator ||= "\n"
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"
207
208
 
208
- if not contents.kind_of? ::Enumerable and not contents.instance_of? ::Hash
209
+ if not contents.kind_of? ::Enumerable and not contents.instance_of? ::Hash
209
210
 
210
- raise ArgumentError, "writelines() must be passed a #{::String}, or a #{::Hash}, or an #{::Enumerable} (or derived)"
211
- end
211
+ raise ArgumentError, "writelines() must be passed a #{::String}, or a #{::Hash}, or an #{::Enumerable} (or derived)"
212
+ end
212
213
 
213
- # do the writing
214
+ # do the writing
214
215
 
215
- if ::String === target
216
+ if ::String === target
216
217
 
217
- File.open(target, "w") do |io|
218
+ File.open(target, "w") do |io|
218
219
 
219
- self.write_to_target_ io, contents, line_separator, column_separator, no_last_eol
220
- end
221
- else
220
+ self.write_to_target_ io, contents, line_separator, column_separator, no_last_eol
221
+ end
222
+ else
222
223
 
223
- self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol
224
- end
225
- end # writelines
224
+ self.write_to_target_ target, contents, line_separator, column_separator, no_last_eol
225
+ end
226
+ end # writelines
226
227
  end # module IO
227
228
  end # module Xqsr3
228
229
 
229
230
  # ############################## end of file ############################# #
230
231
 
231
-