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.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/examples/count_word_frequencies.md +13 -13
- data/examples/count_word_frequencies.rb +5 -5
- data/lib/xqsr3/array_utilities/join_with_or.rb +53 -54
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -67
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +405 -404
- data/lib/xqsr3/containers/multi_map.rb +454 -453
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +56 -57
- data/lib/xqsr3/conversion/integer_parser.rb +92 -93
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +152 -151
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +99 -95
- data/lib/xqsr3/diagnostics/inspect_builder.rb +86 -86
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +136 -136
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +18 -17
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +41 -41
- data/lib/xqsr3/extensions/enumerable/unique.rb +32 -31
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
- data/lib/xqsr3/extensions/hash/except.rb +16 -16
- data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
- data/lib/xqsr3/extensions/hash/match.rb +10 -10
- data/lib/xqsr3/extensions/hash/slice.rb +11 -11
- data/lib/xqsr3/extensions/hash.rb +1 -1
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
- data/lib/xqsr3/extensions/integer.rb +3 -0
- data/lib/xqsr3/extensions/io/writelines.rb +34 -34
- data/lib/xqsr3/extensions/kernel/integer.rb +26 -26
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +15 -14
- data/lib/xqsr3/extensions/kernel.rb +1 -0
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
- data/lib/xqsr3/extensions/string/map_option_string.rb +4 -5
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -2
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -9
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -2
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -62
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -38
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +71 -71
- data/lib/xqsr3/hash_utilities/key_matching.rb +82 -82
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +130 -88
- data/lib/xqsr3/io/writelines.rb +125 -125
- data/lib/xqsr3/quality/parameter_checking.rb +452 -453
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +64 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +33 -34
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +35 -35
- data/lib/xqsr3/string_utilities/quote_if.rb +55 -56
- data/lib/xqsr3/string_utilities/starts_with.rb +64 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +80 -80
- data/lib/xqsr3/string_utilities/truncate.rb +60 -61
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +19 -20
- data/test/performance/frequency_map.rb +13 -27
- data/test/scratch/test_assert_raise_with_message.rb +12 -13
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -142
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +607 -554
- data/test/unit/containers/tc_multi_map.rb +573 -522
- data/test/unit/conversion/tc_integer_parser.rb +73 -73
- data/test/unit/conversion/tc_to_bool.rb +26 -26
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
- data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
- data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
- data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
- data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
- data/test/unit/extensions/hash/tc_except.rb +28 -28
- data/test/unit/extensions/hash/tc_hash.rb +1 -1
- data/test/unit/extensions/hash/tc_slice.rb +14 -14
- data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
- data/test/unit/extensions/integer/ts_all.rb +12 -0
- data/test/unit/extensions/io/tc_writelines.rb +77 -77
- data/test/unit/extensions/kernel/tc_integer.rb +75 -75
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
- data/test/unit/extensions/object/tc_inspect.rb +51 -51
- data/test/unit/extensions/string/tc_bool.tb +24 -24
- data/test/unit/extensions/string/tc_ends_with.rb +53 -53
- data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
- data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
- data/test/unit/extensions/string/tc_quote_if.rb +18 -18
- data/test/unit/extensions/string/tc_starts_with.rb +53 -53
- data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
- data/test/unit/extensions/string/tc_truncate.rb +18 -18
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
- data/test/unit/hash_utilities/tc_has_match.rb +70 -70
- data/test/unit/hash_utilities/tc_match.rb +83 -83
- data/test/unit/io/tc_writelines.rb +106 -108
- data/test/unit/quality/tc_parameter_checking.rb +390 -390
- data/test/unit/string_utilities/tc_truncate.rb +28 -28
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -1,133 +1,176 @@
|
|
1
1
|
|
2
|
-
#
|
3
|
-
#
|
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
|
-
|
52
|
+
require 'test/unit/version'
|
10
53
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
rescue LoadError
|
68
|
+
# :startdoc:
|
69
|
+
rescue LoadError
|
27
70
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
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
|
-
|
94
|
+
if TEST_UNIT_VERSION_ == :not_found
|
52
95
|
|
53
|
-
|
96
|
+
TEST_UNIT_VERSION_PARTS_ = []
|
54
97
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
103
|
+
TEST_UNIT_VERSION_PARTS_ = TEST_UNIT_VERSION_.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
61
104
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
|
110
|
+
# @!visibility private
|
111
|
+
def self.less_ a1, a2 # :nodoc:
|
69
112
|
|
70
|
-
|
113
|
+
n_common = a1.size < a2.size ? a1.size : a2.size
|
71
114
|
|
72
|
-
|
115
|
+
(0...n_common).each do |ix|
|
73
116
|
|
74
|
-
|
75
|
-
|
117
|
+
v1 = a1[ix]
|
118
|
+
v2 = a2[ix]
|
76
119
|
|
77
|
-
|
120
|
+
if v1 == v2
|
78
121
|
|
79
|
-
|
80
|
-
|
122
|
+
next
|
123
|
+
end
|
81
124
|
|
82
|
-
|
125
|
+
if v1 < v2
|
83
126
|
|
84
|
-
|
85
|
-
|
127
|
+
return true
|
128
|
+
else
|
86
129
|
|
87
|
-
|
88
|
-
|
89
|
-
|
130
|
+
return false
|
131
|
+
end
|
132
|
+
end
|
90
133
|
|
91
|
-
|
134
|
+
if n_common != a2.size
|
92
135
|
|
93
|
-
|
94
|
-
|
136
|
+
return true
|
137
|
+
else
|
95
138
|
|
96
|
-
|
97
|
-
|
98
|
-
|
139
|
+
return false
|
140
|
+
end
|
141
|
+
end
|
99
142
|
|
100
|
-
|
101
|
-
|
143
|
+
# @!visibility private
|
144
|
+
def self.is_major_at_least? j # :nodoc:
|
102
145
|
|
103
|
-
|
146
|
+
return unless TEST_UNIT_VERSION_MAJOR_
|
104
147
|
|
105
|
-
|
106
|
-
|
148
|
+
return j >= TEST_UNIT_VERSION_MAJOR_
|
149
|
+
end
|
107
150
|
|
108
|
-
|
109
|
-
|
151
|
+
# @!visibility private
|
152
|
+
def self.is_minor_at_least? n # :nodoc:
|
110
153
|
|
111
|
-
|
154
|
+
return unless TEST_UNIT_VERSION_MINOR_
|
112
155
|
|
113
|
-
|
114
|
-
|
156
|
+
return n >= TEST_UNIT_VERSION_MINOR_
|
157
|
+
end
|
115
158
|
|
116
|
-
|
117
|
-
|
159
|
+
# @!visibility private
|
160
|
+
def self.is_at_least? v # :nodoc:
|
118
161
|
|
119
|
-
|
162
|
+
v = v.split(/\./).collect { |n| n.to_i } if String === v
|
120
163
|
|
121
|
-
|
122
|
-
|
164
|
+
return !less_(TEST_UNIT_VERSION_PARTS_, v)
|
165
|
+
end
|
123
166
|
|
124
|
-
|
125
|
-
|
167
|
+
# @!visibility private
|
168
|
+
def self.is_less? v # :nodoc:
|
126
169
|
|
127
|
-
|
170
|
+
v = v.split(/\./).collect { |n| n.to_i } if String === v
|
128
171
|
|
129
|
-
|
130
|
-
|
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
|
-
|
data/lib/xqsr3/io/writelines.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/io/writelines.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Adds a writelines() method to the IO module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 13th April 2007
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
|
-
# Author:
|
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
|
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
|
-
|
59
|
-
|
60
|
-
|
59
|
+
private
|
60
|
+
# @!visibility private
|
61
|
+
module WriteLine_Constants_ #:nodoc: all
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
NUMBER_OF_LINES_TO_EXAMINE = 20
|
64
|
+
end # module WriteLine_Constants_
|
64
65
|
|
65
|
-
|
66
|
+
private
|
66
67
|
|
67
|
-
|
68
|
-
|
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
|
-
|
73
|
+
if no_last_eol
|
73
74
|
|
74
|
-
|
75
|
+
first = true
|
75
76
|
|
76
|
-
|
77
|
+
if contents.instance_of? ::Hash
|
77
78
|
|
78
|
-
|
79
|
+
contents.each do |k, v|
|
79
80
|
|
80
|
-
|
81
|
+
target << line_separator unless first
|
81
82
|
|
82
|
-
|
83
|
+
target << "#{k}#{column_separator}#{v}"
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
first = false
|
86
|
+
end
|
87
|
+
else
|
87
88
|
|
88
|
-
|
89
|
+
contents.each do |element|
|
89
90
|
|
90
|
-
|
91
|
+
target << line_separator unless first
|
91
92
|
|
92
|
-
|
93
|
+
target << "#{element}"
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
first = false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
else
|
98
99
|
|
99
|
-
|
100
|
+
if contents.instance_of? ::Hash
|
100
101
|
|
101
|
-
|
102
|
+
contents.each do |k, v|
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
target << "#{k}#{column_separator}#{v}#{line_separator}"
|
105
|
+
end
|
106
|
+
else
|
106
107
|
|
107
|
-
|
108
|
+
contents.each do |element|
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
target << "#{element}#{line_separator}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
113
114
|
|
114
|
-
|
115
|
-
|
115
|
+
contents.size
|
116
|
+
end
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
126
|
+
if contents.instance_of? ::Hash
|
126
127
|
|
127
|
-
|
128
|
+
contents.each_with_index do |k, v, index|
|
128
129
|
|
129
|
-
|
130
|
+
if eol_lookahead_limit && eol_lookahead_limit == index
|
130
131
|
|
131
|
-
|
132
|
-
|
132
|
+
break
|
133
|
+
else
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
141
|
+
contents.each_with_index do |element, index|
|
141
142
|
|
142
|
-
|
143
|
+
if eol_lookahead_limit && eol_lookahead_limit == index
|
143
144
|
|
144
|
-
|
145
|
-
|
145
|
+
break
|
146
|
+
else
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
return '' if element.to_s.include? "\n"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
151
152
|
|
152
|
-
|
153
|
-
|
153
|
+
"\n"
|
154
|
+
end
|
154
155
|
|
155
|
-
|
156
|
+
public
|
156
157
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
178
|
+
# validate parameters
|
178
179
|
|
179
|
-
|
180
|
+
::Xqsr3::Quality::ParameterChecking.check_parameter(target, 'target', allow_nil: false) do |v|
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
187
|
+
# process parameters
|
187
188
|
|
188
|
-
|
189
|
+
if contents.instance_of? String
|
189
190
|
|
190
|
-
|
191
|
+
if contents.include? "\n"
|
191
192
|
|
192
|
-
|
193
|
-
|
193
|
+
contents = contents.split(/\r?\n/, -1)
|
194
|
+
else
|
194
195
|
|
195
|
-
|
196
|
-
|
197
|
-
|
196
|
+
contents = [ contents ]
|
197
|
+
end
|
198
|
+
end
|
198
199
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
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
|
-
|
209
|
+
if not contents.kind_of? ::Enumerable and not contents.instance_of? ::Hash
|
209
210
|
|
210
|
-
|
211
|
-
|
211
|
+
raise ArgumentError, "writelines() must be passed a #{::String}, or a #{::Hash}, or an #{::Enumerable} (or derived)"
|
212
|
+
end
|
212
213
|
|
213
|
-
|
214
|
+
# do the writing
|
214
215
|
|
215
|
-
|
216
|
+
if ::String === target
|
216
217
|
|
217
|
-
|
218
|
+
File.open(target, "w") do |io|
|
218
219
|
|
219
|
-
|
220
|
-
|
221
|
-
|
220
|
+
self.write_to_target_ io, contents, line_separator, column_separator, no_last_eol
|
221
|
+
end
|
222
|
+
else
|
222
223
|
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|