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,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: lib/xqsr3/extensions/enumerable/detect_map.rb
3
+ # File: lib/xqsr3/extensions/enumerable/detect_map.rb
4
4
  #
5
- # Purpose: ::Enumerable#detect_map extension
5
+ # Purpose: ::Enumerable#detect_map extension
6
6
  #
7
- # Created: 3rd December 2017
8
- # Updated: 12th April 2019
7
+ # Created: 3rd December 2017
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) 2017-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
  #
@@ -49,48 +50,47 @@
49
50
 
50
51
  module Enumerable
51
52
 
52
- # The +Enumerable+#+detect+ method provides a way to detect the presence
53
- # of a particular value in a collection. The only constraint is that you
54
- # get back the object unchanged.
55
- #
56
- # The +Enumerable+#+map+ method provides a way to transform the contents of
57
- # a collection. The only constraint is that you get back another
58
- # collection.
59
- #
60
- # This extension method, +Enumerable+#+detect_map+ combines the features
61
- # of both, in that it detects the presence of a particular value in a
62
- # collection and transform the detected value.
63
- #
64
- # [ 1, 2, 3 ].detect_map { |v| -2 * v if v > 2 } # => -6
65
- #
66
- # { :ab => 'cd', :ef => 'gh' }.detect_map { |k, v| v.upcase if k == :ef } # => 'GH'
67
- #
68
- # *Note:* The block is required (for technical reasons), and must have
69
- # arity 1 for sequences or 2 for associations
70
- def detect_map &block
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
71
72
 
72
- case block.arity
73
- when 1
73
+ case block.arity
74
+ when 1
74
75
 
75
- self.each do |v|
76
+ self.each do |v|
76
77
 
77
- r = yield(v) and return r
78
- end
79
- when 2
78
+ r = yield(v) and return r
79
+ end
80
+ when 2
80
81
 
81
- self.each do |k, v|
82
+ self.each do |k, v|
82
83
 
83
- r = yield(k, v) and return r
84
- end
85
- else
84
+ r = yield(k, v) and return r
85
+ end
86
+ else
86
87
 
87
- 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}"
88
- end
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
89
90
 
90
- nil
91
- end
91
+ nil
92
+ end
92
93
  end # module Enumerable
93
94
 
94
95
  # ############################## end of file ############################# #
95
96
 
96
-
@@ -1,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: lib/xqsr3/extensions/enumerable/unique.rb
3
+ # File: lib/xqsr3/extensions/enumerable/unique.rb
4
4
  #
5
- # Purpose: Adds a unique() method to the Enumerable module
5
+ # Purpose: Adds a unique() method to the Enumerable module
6
6
  #
7
- # Created: 5th March 2007
8
- # Updated: 12th April 2019
7
+ # Created: 5th March 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
  #
@@ -52,40 +53,40 @@
52
53
 
53
54
  module Enumerable
54
55
 
55
- # Removes all duplicate elements in a sequence subject to an optional
56
- # two-parameter block in order to return an array containing unique
57
- # elements
58
- #
59
- # [ 1, 2, 3 ].unique # => [ 1, 2, 3 ]
60
- # [ 1, 2, 1, 3 ].unique # => [ 1, 2, 3 ]
61
- def unique(&block)
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
- if not block
64
+ if not block
64
65
 
65
- return unique { |a, b| a == b }
66
- else
66
+ return unique { |a, b| a == b }
67
+ else
67
68
 
68
- raise ArgumentError, "block requires two parameters" unless block.arity == 2
69
+ raise ArgumentError, "block requires two parameters" unless block.arity == 2
69
70
 
70
- ar = self.to_a
71
+ ar = self.to_a
71
72
 
72
- return ar if ar.length < 2
73
+ return ar if ar.length < 2
73
74
 
74
- r = []
75
- h = {}
75
+ r = []
76
+ h = {}
76
77
 
77
- ar.each do |v|
78
+ ar.each do |v|
78
79
 
79
- unless h.has_key?(v)
80
+ unless h.has_key?(v)
80
81
 
81
- r << v
82
- h[v] = nil
83
- end
84
- end
82
+ r << v
83
+ h[v] = nil
84
+ end
85
+ end
85
86
 
86
- return r
87
- end
88
- end
87
+ return r
88
+ end
89
+ end
89
90
  end # module Enumerable
90
91
 
91
92
  # ############################## end of file ############################# #
@@ -3,6 +3,6 @@ require 'xqsr3/hash_utilities/deep_transform'
3
3
 
4
4
  class Hash
5
5
 
6
- include ::Xqsr3::HashUtilities::DeepTransform
6
+ include ::Xqsr3::HashUtilities::DeepTransform
7
7
  end # class Hash
8
8
 
@@ -1,32 +1,32 @@
1
1
 
2
2
  unless Hash.instance_methods.include? :except!
3
3
 
4
- class Hash
4
+ class Hash
5
5
 
6
- # Removes from the instance any key-value pairs matching the
7
- # keys specified in +keys_to_delete+
8
- def except!(*keys_to_delete)
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
- keys_to_delete.each do |key|
10
+ keys_to_delete.each do |key|
11
11
 
12
- self.delete key
13
- end
12
+ self.delete key
13
+ end
14
14
 
15
- self
16
- end
15
+ self
16
+ end
17
17
  end
18
18
  end
19
19
 
20
20
  unless Hash.instance_methods.include? :except
21
21
 
22
- class Hash
22
+ class Hash
23
23
 
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)
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
- self.dup.except!(*keys_to_delete)
29
- end
30
- end
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
- # 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
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
- return ::Xqsr3::HashUtilities::KeyMatching.has_match? self, re, **options
16
- end
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
- # 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
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
- return ::Xqsr3::HashUtilities::KeyMatching.match self, re, **options
16
- end
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
- class Hash
4
+ class Hash
5
5
 
6
- def slice(*args)
6
+ def slice(*args)
7
7
 
8
- r = {}
8
+ r = {}
9
9
 
10
- args.each do |arg|
10
+ args.each do |arg|
11
11
 
12
- if self.has_key? arg
12
+ if self.has_key? arg
13
13
 
14
- r[arg] = self[arg]
15
- end
16
- end
14
+ r[arg] = self[arg]
15
+ end
16
+ end
17
17
 
18
- r
19
- end
20
- end
18
+ r
19
+ end
20
+ end
21
21
  end
22
22
 
@@ -6,6 +6,6 @@ require 'xqsr3/extensions/hash/match'
6
6
 
7
7
  unless (RUBY_VERSION.split('.').map { |v| v.to_i } <=> [ 2, 5, 0 ]) > 0
8
8
 
9
- require 'xqsr3/extensions/hash/slice'
9
+ require 'xqsr3/extensions/hash/slice'
10
10
  end
11
11
 
@@ -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
+
@@ -0,0 +1,3 @@
1
+
2
+ require 'xqsr3/extensions/integer/to_s_grp'
3
+
@@ -1,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: lib/xqsr3/extensions/io/writelines.rb
3
+ # File: lib/xqsr3/extensions/io/writelines.rb
4
4
  #
5
- # Purpose: Adds a writelines() method to the IO class
5
+ # Purpose: Adds a writelines() method to the IO class
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
  #
@@ -54,45 +55,44 @@ require 'xqsr3/io/writelines'
54
55
 
55
56
  class IO
56
57
 
57
- # Extends +IO+ class with the +::Xqsr3::IO::write_lines+ method
58
- #
59
- #
60
- #def self.writelines(path, contents, lineSep = nil, columnSep = nil)
61
- def self.writelines(path, contents, *args)
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)
62
63
 
63
- options = {}
64
+ options = {}
64
65
 
65
- case args.size
66
- when 0
66
+ case args.size
67
+ when 0
67
68
 
68
- ;
69
- when 1
69
+ ;
70
+ when 1
70
71
 
71
- arg3 = args[0]
72
+ arg3 = args[0]
72
73
 
73
- if arg3.respond_to?(:to_hash)
74
+ if arg3.respond_to?(:to_hash)
74
75
 
75
- options.merge! arg3.to_hash
76
- else
76
+ options.merge! arg3.to_hash
77
+ else
77
78
 
78
- options[:line_separator] = arg3
79
- end
80
- when 2
79
+ options[:line_separator] = arg3
80
+ end
81
+ when 2
81
82
 
82
- arg3 = args[0]
83
- arg4 = args[1]
83
+ arg3 = args[0]
84
+ arg4 = args[1]
84
85
 
85
- options[:line_separator] = arg2
86
- options[:column_separator] = arg2
87
- else
86
+ options[:line_separator] = arg2
87
+ options[:column_separator] = arg2
88
+ else
88
89
 
89
- raise ArgumentError, "wrong number of arguments (given #{2 + args.size}, expected 2..4)"
90
- end
90
+ raise ArgumentError, "wrong number of arguments (given #{2 + args.size}, expected 2..4)"
91
+ end
91
92
 
92
- ::Xqsr3::IO.writelines path, contents, **options
93
- end
93
+ ::Xqsr3::IO.writelines path, contents, **options
94
+ end
94
95
  end # class IO
95
96
 
96
97
  # ############################## end of file ############################# #
97
98
 
98
-