xqsr3 0.38.2 → 0.39.2
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 +12 -12
- data/examples/count_word_frequencies.rb +4 -4
- data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +399 -399
- data/lib/xqsr3/containers/multi_map.rb +448 -448
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +51 -51
- data/lib/xqsr3/conversion/integer_parser.rb +87 -87
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
- data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +130 -130
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
- data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
- 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 +28 -28
- data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
- 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 -4
- 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 -1
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -1
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
- data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
- data/lib/xqsr3/io/writelines.rb +122 -120
- data/lib/xqsr3/quality/parameter_checking.rb +445 -445
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
- data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
- data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
- data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
- data/lib/xqsr3/string_utilities/truncate.rb +55 -55
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +12 -12
- data/test/performance/frequency_map.rb +12 -12
- data/test/scratch/test_assert_raise_with_message.rb +11 -11
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +591 -591
- data/test/unit/containers/tc_multi_map.rb +558 -558
- data/test/unit/conversion/tc_integer_parser.rb +72 -72
- data/test/unit/conversion/tc_to_bool.rb +25 -25
- 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_slice.rb +13 -13
- 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 +149 -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 +50 -50
- 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 +166 -106
- data/test/unit/quality/tc_parameter_checking.rb +389 -389
- data/test/unit/string_utilities/tc_truncate.rb +27 -27
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: ::Enumerable#detect_map extension
|
6
6
|
#
|
7
7
|
# Created: 3rd December 2017
|
8
|
-
# Updated:
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2019-
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
15
|
# Copyright (c) 2017-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -50,46 +50,46 @@
|
|
50
50
|
|
51
51
|
module Enumerable
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
53
|
+
# The +Enumerable+#+detect+ method provides a way to detect the presence
|
54
|
+
# of a particular value in a collection. The only constraint is that you
|
55
|
+
# get back the object unchanged.
|
56
|
+
#
|
57
|
+
# The +Enumerable+#+map+ method provides a way to transform the contents of
|
58
|
+
# a collection. The only constraint is that you get back another
|
59
|
+
# collection.
|
60
|
+
#
|
61
|
+
# This extension method, +Enumerable+#+detect_map+ combines the features
|
62
|
+
# of both, in that it detects the presence of a particular value in a
|
63
|
+
# collection and transform the detected value.
|
64
|
+
#
|
65
|
+
# [ 1, 2, 3 ].detect_map { |v| -2 * v if v > 2 } # => -6
|
66
|
+
#
|
67
|
+
# { :ab => 'cd', :ef => 'gh' }.detect_map { |k, v| v.upcase if k == :ef } # => 'GH'
|
68
|
+
#
|
69
|
+
# *Note:* The block is required (for technical reasons), and must have
|
70
|
+
# arity 1 for sequences or 2 for associations
|
71
|
+
def detect_map &block
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
case block.arity
|
74
|
+
when 1
|
75
75
|
|
76
|
-
|
76
|
+
self.each do |v|
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
r = yield(v) and return r
|
79
|
+
end
|
80
|
+
when 2
|
81
81
|
|
82
|
-
|
82
|
+
self.each do |k, v|
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
r = yield(k, v) and return r
|
85
|
+
end
|
86
|
+
else
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
raise ArgumentError, "detect_map requires block with arity of 1 (for sequences) or 2 (for associations); block with arity #{block.arity} given to instance of #{self.class}"
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
nil
|
92
|
+
end
|
93
93
|
end # module Enumerable
|
94
94
|
|
95
95
|
# ############################## end of file ############################# #
|
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/extensions/enumerable/unique.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Adds a unique() method to the Enumerable module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 5th March 2007
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
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
|
#
|
@@ -52,40 +53,40 @@
|
|
52
53
|
|
53
54
|
module Enumerable
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
# Removes all duplicate elements in a sequence subject to an optional
|
57
|
+
# two-parameter block in order to return an array containing unique
|
58
|
+
# elements
|
59
|
+
#
|
60
|
+
# [ 1, 2, 3 ].unique # => [ 1, 2, 3 ]
|
61
|
+
# [ 1, 2, 1, 3 ].unique # => [ 1, 2, 3 ]
|
62
|
+
def unique(&block)
|
62
63
|
|
63
|
-
|
64
|
+
if not block
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
return unique { |a, b| a == b }
|
67
|
+
else
|
67
68
|
|
68
|
-
|
69
|
+
raise ArgumentError, "block requires two parameters" unless block.arity == 2
|
69
70
|
|
70
|
-
|
71
|
+
ar = self.to_a
|
71
72
|
|
72
|
-
|
73
|
+
return ar if ar.length < 2
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
r = []
|
76
|
+
h = {}
|
76
77
|
|
77
|
-
|
78
|
+
ar.each do |v|
|
78
79
|
|
79
|
-
|
80
|
+
unless h.has_key?(v)
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
r << v
|
83
|
+
h[v] = nil
|
84
|
+
end
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
return r
|
88
|
+
end
|
89
|
+
end
|
89
90
|
end # module Enumerable
|
90
91
|
|
91
92
|
# ############################## end of file ############################# #
|
@@ -1,32 +1,32 @@
|
|
1
1
|
|
2
2
|
unless Hash.instance_methods.include? :except!
|
3
3
|
|
4
|
-
|
4
|
+
class Hash
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# Removes from the instance any key-value pairs matching the
|
7
|
+
# keys specified in +keys_to_delete+
|
8
|
+
def except!(*keys_to_delete)
|
9
9
|
|
10
|
-
|
10
|
+
keys_to_delete.each do |key|
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
self.delete key
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
end
|
15
|
+
self
|
17
16
|
end
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
unless Hash.instance_methods.include? :except
|
21
21
|
|
22
|
-
|
22
|
+
class Hash
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# Obtains a copy of the instance wherein any key-value pairs
|
25
|
+
# matching the keys specified in +keys_to_delete+ are removed
|
26
|
+
def except(*keys_to_delete)
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
self.dup.except!(*keys_to_delete)
|
29
|
+
end
|
30
|
+
end
|
31
31
|
end
|
32
32
|
|
@@ -3,16 +3,16 @@ require 'xqsr3/hash_utilities/key_matching'
|
|
3
3
|
|
4
4
|
class Hash
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
# Extended method implemented by Xqsr3::HashUtilities::KeyMatching
|
7
|
+
#
|
8
|
+
# === Signature
|
9
|
+
#
|
10
|
+
# * *Parameters:*
|
11
|
+
# - +re+ (Regexp) The regular expression
|
12
|
+
# - +options+ (Hash) See Xqsr3::HashUtilities::KeyMatching
|
13
|
+
def has_match? re, **options
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
return ::Xqsr3::HashUtilities::KeyMatching.has_match? self, re, **options
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
@@ -3,16 +3,16 @@ require 'xqsr3/hash_utilities/key_matching'
|
|
3
3
|
|
4
4
|
class Hash
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
# Extended method implemented by Xqsr3::HashUtilities::KeyMatching
|
7
|
+
#
|
8
|
+
# === Signature
|
9
|
+
#
|
10
|
+
# * *Parameters:*
|
11
|
+
# - +re+ (Regexp) The regular expression
|
12
|
+
# - +options+ (Hash) See Xqsr3::HashUtilities::KeyMatching
|
13
|
+
def match re, **options
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
return ::Xqsr3::HashUtilities::KeyMatching.match self, re, **options
|
16
|
+
end
|
17
17
|
end
|
18
18
|
|
@@ -1,22 +1,22 @@
|
|
1
1
|
|
2
2
|
unless Hash.instance_methods.include? :slice
|
3
3
|
|
4
|
-
|
4
|
+
class Hash
|
5
5
|
|
6
|
-
|
6
|
+
def slice(*args)
|
7
7
|
|
8
|
-
|
8
|
+
r = {}
|
9
9
|
|
10
|
-
|
10
|
+
args.each do |arg|
|
11
11
|
|
12
|
-
|
12
|
+
if self.has_key? arg
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
r[arg] = self[arg]
|
15
|
+
end
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
r
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,118 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: lib/xqsr3/extensions/integer/to_s_grp.rb
|
4
|
+
#
|
5
|
+
# Purpose: Adds a to_s_grp() method to the Integer class
|
6
|
+
#
|
7
|
+
# Created: 29th March 2024
|
8
|
+
# Updated: 29th March 2024
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2024, Matthew Wilson and Synesis Information Systems
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
# ##########################################################
|
48
|
+
# ::Integer
|
49
|
+
|
50
|
+
=begin
|
51
|
+
=end
|
52
|
+
|
53
|
+
class Integer
|
54
|
+
|
55
|
+
# Extends +Integer+ type with the +#to_s_grp()+ method
|
56
|
+
def to_s_grp *args, **options
|
57
|
+
|
58
|
+
separator = options[:separator] || ','
|
59
|
+
|
60
|
+
numbers =
|
61
|
+
case args.size
|
62
|
+
when 0
|
63
|
+
|
64
|
+
[]
|
65
|
+
when 1
|
66
|
+
case args[0]
|
67
|
+
when ::Array
|
68
|
+
|
69
|
+
args[0]
|
70
|
+
when ::Integer
|
71
|
+
|
72
|
+
[ args[0] ]
|
73
|
+
else
|
74
|
+
|
75
|
+
raise TypeError, "parameter 'args[0]' (#{args[0].class}) must be an instance of Integer, or an array containing instance(s) of Integer"
|
76
|
+
end
|
77
|
+
else
|
78
|
+
|
79
|
+
args
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
case numbers.size
|
84
|
+
when 0
|
85
|
+
|
86
|
+
return self.to_s
|
87
|
+
when 1
|
88
|
+
|
89
|
+
return self.to_s.chars.to_a.reverse.each_slice(numbers[0]).map(&:join).join(',').reverse
|
90
|
+
else
|
91
|
+
|
92
|
+
reversed_chars = self.to_s.chars.to_a#.reverse
|
93
|
+
|
94
|
+
r = []
|
95
|
+
|
96
|
+
last_n = nil
|
97
|
+
|
98
|
+
numbers.each do |n|
|
99
|
+
|
100
|
+
r << separator unless r.empty?
|
101
|
+
r << reversed_chars.pop(n).reverse
|
102
|
+
|
103
|
+
last_n = n
|
104
|
+
end
|
105
|
+
|
106
|
+
until reversed_chars.empty?
|
107
|
+
|
108
|
+
r << separator unless r.empty?
|
109
|
+
r << reversed_chars.pop(last_n).reverse
|
110
|
+
end
|
111
|
+
|
112
|
+
r.flatten.join('').reverse
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end # module Kernel
|
116
|
+
|
117
|
+
# ############################## end of file ############################# #
|
118
|
+
|
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Adds a writelines() method to the IO class
|
6
6
|
#
|
7
7
|
# Created: 13th April 2007
|
8
|
-
# Updated:
|
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-
|
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
|
#
|
@@ -55,43 +55,43 @@ require 'xqsr3/io/writelines'
|
|
55
55
|
|
56
56
|
class IO
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
# Extends +IO+ class with the +::Xqsr3::IO::write_lines+ method
|
59
|
+
#
|
60
|
+
#
|
61
|
+
#def self.writelines(path, contents, lineSep = nil, columnSep = nil)
|
62
|
+
def self.writelines(path, contents, *args)
|
63
63
|
|
64
|
-
|
64
|
+
options = {}
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
case args.size
|
67
|
+
when 0
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
;
|
70
|
+
when 1
|
71
71
|
|
72
|
-
|
72
|
+
arg3 = args[0]
|
73
73
|
|
74
|
-
|
74
|
+
if arg3.respond_to?(:to_hash)
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
options.merge! arg3.to_hash
|
77
|
+
else
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
options[:line_separator] = arg3
|
80
|
+
end
|
81
|
+
when 2
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
arg3 = args[0]
|
84
|
+
arg4 = args[1]
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
options[:line_separator] = arg3
|
87
|
+
options[:column_separator] = arg4
|
88
|
+
else
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
raise ArgumentError, "wrong number of arguments (given #{2 + args.size}, expected 2..4)"
|
91
|
+
end
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
::Xqsr3::IO.writelines path, contents, **options
|
94
|
+
end
|
95
95
|
end # class IO
|
96
96
|
|
97
97
|
# ############################## end of file ############################# #
|
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Adds a Integer 'overload' to the Kernel module
|
6
6
|
#
|
7
7
|
# Created: 21st November 2017
|
8
|
-
# Updated:
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2019-
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
15
|
# Copyright (c) 2017-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -55,27 +55,27 @@ require 'xqsr3/conversion/integer_parser'
|
|
55
55
|
|
56
56
|
module Kernel
|
57
57
|
|
58
|
-
|
58
|
+
alias xqsr3_Integer_original_method Integer
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
60
|
+
# A monkey-patch extension of +Kernel#Integer+ with +options+
|
61
|
+
#
|
62
|
+
# === Signature
|
63
|
+
#
|
64
|
+
# * *Parameters:*
|
65
|
+
# - +arg+ The argument to be converted (to +Fixnum+ or +Bignum+)
|
66
|
+
# - +base+ A value of 0, or between 2 and 36. Defaults to 0
|
67
|
+
# - +options+ An options hash, containing any of the following options
|
68
|
+
# - +block+ An optional caller-supplied block that will be invoked with the +ArgumentError+ exception, allowing the caller to take additional action. If the block returns then its return value will be returned to the caller
|
69
|
+
#
|
70
|
+
# * *Options:*
|
71
|
+
# - +:default+ A default value to be used when +arg+ is +nil+ or cannot be converted by (the original) +Kernel#Integer+
|
72
|
+
# - +:nil+ Returns +nil+ if +arg+ is +nil+ or cannot be converted by (the original) +Kernel#Integer+. Ignored if +:default+ is specified
|
73
|
+
def Integer(arg, base = 0, **options, &block)
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
::Xqsr3::Conversion::IntegerParser.to_integer arg, base = 0, **options, &block
|
76
|
+
end
|
77
77
|
|
78
|
-
|
78
|
+
private :xqsr3_Integer_original_method
|
79
79
|
end # module Kernel
|
80
80
|
|
81
81
|
# ############################## end of file ############################# #
|
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Adds a raise_with_options() method to the Kernel module
|
6
6
|
#
|
7
7
|
# Created: 12th February 2015
|
8
|
-
# Updated:
|
8
|
+
# Updated: 29th March 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2019-
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
15
15
|
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -55,14 +55,14 @@ require 'xqsr3/diagnostics/exception_utilities'
|
|
55
55
|
|
56
56
|
module Kernel
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
# Extends +Kernel+ module with the ::Xqsr3::Diagnostics::ExceptionUtilities::raise_with_options
|
59
|
+
# method
|
60
|
+
def raise_with_options *args, **options
|
61
61
|
|
62
|
-
|
62
|
+
options ||= {}
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
::Xqsr3::Diagnostics::ExceptionUtilities.raise_with_options(*args, **(options.merge({ :called_indirectly_06d353cb_5a6c_47ca_8dbe_ff76359c7e96 => 1})))
|
65
|
+
end
|
66
66
|
end # module Kernel
|
67
67
|
|
68
68
|
# ############################## end of file ############################# #
|