xqsr3 0.39.2 → 0.39.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/examples/count_word_frequencies.rb +2 -0
  3. data/lib/xqsr3/array_utilities/join_with_or.rb +50 -53
  4. data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -69
  5. data/lib/xqsr3/containers/frequency_map.rb +408 -394
  6. data/lib/xqsr3/containers/multi_map.rb +464 -446
  7. data/lib/xqsr3/conversion/bool_parser.rb +49 -54
  8. data/lib/xqsr3/conversion/integer_parser.rb +84 -89
  9. data/lib/xqsr3/diagnostics/exception_utilities.rb +127 -132
  10. data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +98 -102
  11. data/lib/xqsr3/diagnostics/inspect_builder.rb +83 -84
  12. data/lib/xqsr3/extensions/array/join_with_or.rb +2 -1
  13. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +1 -4
  14. data/lib/xqsr3/extensions/enumerable/unique.rb +1 -4
  15. data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -0
  16. data/lib/xqsr3/extensions/hash/has_match.rb +3 -2
  17. data/lib/xqsr3/extensions/hash/match.rb +3 -2
  18. data/lib/xqsr3/extensions/integer/to_s_grp.rb +1 -4
  19. data/lib/xqsr3/extensions/io/writelines.rb +1 -4
  20. data/lib/xqsr3/extensions/kernel/integer.rb +7 -9
  21. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +1 -3
  22. data/lib/xqsr3/extensions/string/ends_with.rb +1 -0
  23. data/lib/xqsr3/extensions/string/map_option_string.rb +1 -0
  24. data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -0
  25. data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -0
  26. data/lib/xqsr3/extensions/string/quote_if.rb +1 -0
  27. data/lib/xqsr3/extensions/string/starts_with.rb +1 -0
  28. data/lib/xqsr3/extensions/string/to_bool.rb +1 -0
  29. data/lib/xqsr3/extensions/string/to_symbol.rb +1 -0
  30. data/lib/xqsr3/extensions/string/truncate.rb +1 -0
  31. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +8 -9
  32. data/lib/xqsr3/extensions/test/unit/assert_false.rb +7 -8
  33. data/lib/xqsr3/extensions/test/unit/assert_not.rb +7 -8
  34. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +8 -9
  35. data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +58 -55
  36. data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +8 -9
  37. data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +8 -9
  38. data/lib/xqsr3/extensions/test/unit/assert_true.rb +7 -8
  39. data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -37
  40. data/lib/xqsr3/hash_utilities/deep_transform.rb +63 -67
  41. data/lib/xqsr3/hash_utilities/key_matching.rb +72 -76
  42. data/lib/xqsr3/internal_/test_unit_version_.rb +3 -1
  43. data/lib/xqsr3/io/writelines.rb +8 -10
  44. data/lib/xqsr3/quality/parameter_checking.rb +406 -411
  45. data/lib/xqsr3/string_utilities/ends_with.rb +60 -64
  46. data/lib/xqsr3/string_utilities/nil_if_empty.rb +31 -35
  47. data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +32 -36
  48. data/lib/xqsr3/string_utilities/quote_if.rb +48 -57
  49. data/lib/xqsr3/string_utilities/starts_with.rb +60 -64
  50. data/lib/xqsr3/string_utilities/to_symbol.rb +77 -81
  51. data/lib/xqsr3/string_utilities/truncate.rb +56 -60
  52. data/lib/xqsr3/version.rb +1 -1
  53. data/test/performance/frequency_map.rb +3 -0
  54. data/test/scratch/test_assert_raise_with_message.rb +2 -0
  55. data/test/unit/array_utilities/tc_join_with_or.rb +3 -1
  56. data/test/unit/command_line_utilities/tc_map_option_string.rb +3 -0
  57. data/test/unit/containers/tc_frequency_map.rb +3 -0
  58. data/test/unit/containers/tc_multi_map.rb +3 -0
  59. data/test/unit/conversion/tc_integer_parser.rb +2 -1
  60. data/test/unit/conversion/tc_to_bool.rb +2 -0
  61. data/test/unit/diagnostics/exceptions/tc_with_cause.rb +2 -0
  62. data/test/unit/diagnostics/tc_exception_utilities.rb +2 -0
  63. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +2 -0
  64. data/test/unit/extensions/enumerable/tc_detect_map.rb +2 -1
  65. data/test/unit/extensions/enumerable/tc_unique.rb +2 -0
  66. data/test/unit/extensions/hash/tc_deep_transform.rb +2 -0
  67. data/test/unit/extensions/hash/tc_except.rb +2 -0
  68. data/test/unit/extensions/hash/tc_hash.rb +1 -0
  69. data/test/unit/extensions/hash/tc_slice.rb +2 -0
  70. data/test/unit/extensions/integer/tc_to_s_grp.rb +2 -0
  71. data/test/unit/extensions/io/tc_writelines.rb +14 -0
  72. data/test/unit/extensions/kernel/tc_integer.rb +2 -1
  73. data/test/unit/extensions/kernel/tc_raise_with_options.rb +2 -0
  74. data/test/unit/extensions/object/tc_inspect.rb +2 -0
  75. data/test/unit/extensions/string/tc_bool.tb +2 -0
  76. data/test/unit/extensions/string/tc_ends_with.rb +2 -0
  77. data/test/unit/extensions/string/tc_map_option_string.rb +2 -0
  78. data/test/unit/extensions/string/tc_nil_if_empty.rb +2 -0
  79. data/test/unit/extensions/string/tc_nil_if_whitespace.rb +2 -0
  80. data/test/unit/extensions/string/tc_quote_if.rb +2 -0
  81. data/test/unit/extensions/string/tc_starts_with.rb +2 -0
  82. data/test/unit/extensions/string/tc_to_symbol.rb +2 -0
  83. data/test/unit/extensions/string/tc_truncate.rb +2 -0
  84. data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +2 -0
  85. data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +2 -0
  86. data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +2 -0
  87. data/test/unit/hash_utilities/tc_has_match.rb +1 -0
  88. data/test/unit/hash_utilities/tc_match.rb +1 -0
  89. data/test/unit/io/tc_writelines.rb +3 -0
  90. data/test/unit/quality/tc_parameter_checking.rb +1 -0
  91. data/test/unit/string_utilities/tc_truncate.rb +2 -0
  92. data/test/unit/tc_version.rb +2 -0
  93. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9ed73f4599f60f4dfbbd40d39d1967cccdf74e69b5f317d859128f04777551c
4
- data.tar.gz: 07b8984f99e23d99ce1fd1cd05fc5b553ddb587e732d8b6d0deac758c95644f2
3
+ metadata.gz: 45e7be3a60a6d9752fee2e9923806d69cec535c99ecce3c3207497e4df761735
4
+ data.tar.gz: d1be5a5d287f913bd5f4396f2ecfc32b06185e7ab64f4a4748500c4f47249932
5
5
  SHA512:
6
- metadata.gz: b78b409d39d78d7e8fc44a31db077e8638d64f91545212ad2ed2921b4a39a5f2d1fc266ffb71ed16b7fb3fd48f947923135144401144942774e93a61938715d3
7
- data.tar.gz: a0b0e40fcc75a20cf3f2203920c807819b88270ae1e4cb987166243e829a05a9d1288b7cc1e2923f3895504cf83272cdb89de92be5b053705dcb04be9c63c492
6
+ metadata.gz: cdaaf454c457db16d69d8ecba4923fa16afeb2d01dfec6eab300d53d38907d21559b845e87605c901f9a76982b12567bc8ecfe765aef7d4a42c490bce0ba9cf1
7
+ data.tar.gz: fc31c9538d65af1747b3f8e51a8cb81a9beb45bce9a5170b71da3a603611ec99672ee5efe71b498b242738d8092f02353542ea4f98ab870f721d7616324a2668
@@ -2,8 +2,10 @@
2
2
 
3
3
  # examples/count_word_frequencies.rb
4
4
 
5
+
5
6
  require 'xqsr3/containers/frequency_map'
6
7
 
8
+
7
9
  include Xqsr3::Containers
8
10
 
9
11
 
@@ -5,7 +5,7 @@
5
5
  # Purpose: Definition of the ::Xqsr3::ArrayUtilities::JoinWithOr module
6
6
  #
7
7
  # Created: 7th December 2017
8
- # Updated: 29th March 2024
8
+ # Updated: 12th April 2024
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -45,67 +45,64 @@
45
45
  # ######################################################################## #
46
46
 
47
47
 
48
- # ##########################################################
49
- # ::Xqsr3::ArrayUtilities::JoinWithOr
48
+ require 'xqsr3/quality/parameter_checking'
49
+
50
50
 
51
51
  =begin
52
52
  =end
53
53
 
54
- require 'xqsr3/quality/parameter_checking'
55
-
56
54
  module Xqsr3
57
55
  module ArrayUtilities
58
56
 
59
- # +include+-able module that provides sequence-joining functionality
60
- module JoinWithOr
61
-
62
- extend self
63
-
64
- # Joins an array with grammatical appropriateness (with an 'or')
65
- #
66
- # === Signature
67
- #
68
- # * *Parameters:*
69
- # - +ar+ (Array) The array whose contents are to be joined
70
- # - +options+ (Hash) Options that control the behaviour of the method
71
- #
72
- # * *Options:*
73
- # - +:or+ (String) A string that is used instead of 'or'
74
- # - +:oxford_comma+ (boolean) Determines whether an Oxford comma will be used. Default is +true+
75
- # - +:quote_char+ (String) The quote character. Default is empty string ''
76
- # - +:separator+ (String) The separator character. Default is ','
77
- def join_with_or ar, **options
78
-
79
- ::Xqsr3::Quality::ParameterChecking.check_parameter ar, 'ar', type: ::Array, allow_nil: true
80
- ::Xqsr3::Quality::ParameterChecking.check_parameter options, 'options', type: ::Hash, allow_nil: false
81
-
82
- ::Xqsr3::Quality::ParameterChecking.check_parameter options[:or], ':or', type: ::String, option: true, allow_nil: true
83
- ::Xqsr3::Quality::ParameterChecking.check_parameter options[:oxford_comma], ':oxford_comma', types: [ ::FalseClass, ::TrueClass ], option: true, allow_nil: true
84
- ::Xqsr3::Quality::ParameterChecking.check_parameter options[:quote_char], ':quote_char', type: ::String, option: true, allow_nil: true
85
- ::Xqsr3::Quality::ParameterChecking.check_parameter options[:separator], ':separator', type: ::String, option: true, allow_nil: true
86
-
87
- return '' if ar.nil?
88
- return '' if ar.empty?
89
-
90
- separator = options[:separator] || ','
91
- or_word = options[:or] || 'or'
92
- ox_comma = (options.has_key?(:oxford_comma) && !options[:oxford_comma]) ? '' : separator
93
- quote_char = options[:quote_char]
94
-
95
- ar = ar.map { |v| "#{quote_char}#{v}#{quote_char}" } if quote_char
96
-
97
- case ar.size
98
- when 1
99
- ar[0]
100
- when 2
101
- "#{ar[0]} #{or_word} #{ar[1]}"
102
- else
103
- "#{ar[0...-1].join(separator + ' ')}#{ox_comma} #{or_word} #{ar[-1]}"
57
+ # +include+-able module that provides sequence-joining functionality
58
+ module JoinWithOr
59
+
60
+ extend self
61
+
62
+ # Joins an array with grammatical appropriateness (with an 'or')
63
+ #
64
+ # === Signature
65
+ #
66
+ # * *Parameters:*
67
+ # - +ar+ (+Array+) The array whose contents are to be joined;
68
+ # - +options+ (+Hash+) Options that control the behaviour of the method;
69
+ #
70
+ # * *Options:*
71
+ # - +:or+ (+String+) A string that is used instead of 'or';
72
+ # - +:oxford_comma+ (boolean) Determines whether an Oxford comma will be used. Default is +true+;
73
+ # - +:quote_char+ (+String+) The quote character. Default is empty string '';
74
+ # - +:separator+ (+String+) The separator character. Default is ',';
75
+ def join_with_or ar, **options
76
+
77
+ ::Xqsr3::Quality::ParameterChecking.check_parameter ar, 'ar', type: ::Array, allow_nil: true
78
+ ::Xqsr3::Quality::ParameterChecking.check_parameter options, 'options', type: ::Hash, allow_nil: false
79
+
80
+ ::Xqsr3::Quality::ParameterChecking.check_parameter options[:or], ':or', type: ::String, option: true, allow_nil: true
81
+ ::Xqsr3::Quality::ParameterChecking.check_parameter options[:oxford_comma], ':oxford_comma', types: [ ::FalseClass, ::TrueClass ], option: true, allow_nil: true
82
+ ::Xqsr3::Quality::ParameterChecking.check_parameter options[:quote_char], ':quote_char', type: ::String, option: true, allow_nil: true
83
+ ::Xqsr3::Quality::ParameterChecking.check_parameter options[:separator], ':separator', type: ::String, option: true, allow_nil: true
84
+
85
+ return '' if ar.nil?
86
+ return '' if ar.empty?
87
+
88
+ separator = options[:separator] || ','
89
+ or_word = options[:or] || 'or'
90
+ ox_comma = (options.has_key?(:oxford_comma) && !options[:oxford_comma]) ? '' : separator
91
+ quote_char = options[:quote_char]
92
+
93
+ ar = ar.map { |v| "#{quote_char}#{v}#{quote_char}" } if quote_char
94
+
95
+ case ar.size
96
+ when 1
97
+ ar[0]
98
+ when 2
99
+ "#{ar[0]} #{or_word} #{ar[1]}"
100
+ else
101
+ "#{ar[0...-1].join(separator + ' ')}#{ox_comma} #{or_word} #{ar[-1]}"
102
+ end
104
103
  end
105
- end
106
-
107
- end # module JoinWithOr
108
104
 
105
+ end # module JoinWithOr
109
106
  end # module ArrayUtilities
110
107
  end # module Xqsr3
111
108
 
@@ -6,7 +6,7 @@
6
6
  # module
7
7
  #
8
8
  # Created: 15th April 2016
9
- # Updated: 29th March 2024
9
+ # Updated: 12th April 2024
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/xqsr3
12
12
  #
@@ -46,105 +46,102 @@
46
46
  # ######################################################################## #
47
47
 
48
48
 
49
- # ##########################################################
50
- # ::Xqsr3::CommandLineUtilities::MapOptionString
51
-
52
49
  require 'xqsr3/string_utilities/to_symbol'
53
50
 
51
+
54
52
  =begin
55
53
  =end
56
54
 
57
55
  module Xqsr3
58
56
  module CommandLineUtilities
59
57
 
60
- # +include+-able module providing facilities for mapping strings to options
61
- #
62
- # === Components of interest
63
- # * ::Xqsr3::CommandLineUtilities::MapOptionString.map_option_string_from_string
64
- # * ::Xqsr3::CommandLineUtilities::MapOptionString#map_option_string
65
- module MapOptionString
58
+ # +include+-able module providing facilities for mapping strings to options
59
+ #
60
+ # === Components of interest
61
+ # * ::Xqsr3::CommandLineUtilities::MapOptionString.map_option_string_from_string
62
+ # * ::Xqsr3::CommandLineUtilities::MapOptionString#map_option_string
63
+ module MapOptionString
64
+
65
+ def self.included includer # :nodoc:
66
66
 
67
- def self.included includer # :nodoc:
67
+ raise TypeError, "module #{self} cannot be included into #{includer} because it does not respond to to_str" unless includer.method_defined? :to_str
68
+ end
68
69
 
69
- raise TypeError, "module #{self} cannot be included into #{includer} because it does not respond to to_str" unless includer.method_defined? :to_str
70
- end
70
+ private
71
+ # @!visibility private
72
+ module MapOptionString_Helper_ # :nodoc: all
71
73
 
72
- private
73
- # @!visibility private
74
- module MapOptionString_Helper_ # :nodoc: all
74
+ def self.map_option_string_with_options_ s, option_strings, options
75
75
 
76
- def self.map_option_string_with_options_ s, option_strings, options
76
+ h = {}
77
77
 
78
- h = {}
78
+ option_strings.each do |os|
79
79
 
80
- option_strings.each do |os|
80
+ t = os.dup
81
+ v = os.dup
81
82
 
82
- t = os.dup
83
- v = os.dup
83
+ if t =~ /\[.+?\]/
84
84
 
85
- if t =~ /\[.+?\]/
85
+ k = ''
86
+ v = ''
86
87
 
87
- k = ''
88
- v = ''
88
+ while t =~ /\[(.+?)\]/
89
89
 
90
- while t =~ /\[(.+?)\]/
90
+ k += $1
91
+ v += "#$`#$1"
92
+ t = $'
93
+ end
91
94
 
92
- k += $1
93
- v += "#$`#$1"
94
- t = $'
95
- end
95
+ v += t
96
+ else
96
97
 
97
- v += t
98
- else
98
+ k = v
99
+ end
99
100
 
100
- k = v
101
+ h[k] = v
102
+ h[v] = v
101
103
  end
102
104
 
103
- h[k] = v
104
- h[v] = v
105
- end
105
+ r = h[s]
106
106
 
107
- r = h[s]
107
+ if r
108
108
 
109
- if r
109
+ r = ::Xqsr3::StringUtilities::ToSymbol.string_to_symbol r
110
+ end
110
111
 
111
- r = ::Xqsr3::StringUtilities::ToSymbol.string_to_symbol r
112
+ r
112
113
  end
113
-
114
- r
115
114
  end
116
- end
117
- public
118
-
119
- # Attempts to translate the value of a given string according
120
- # to a collection of options strings
121
- #
122
- # === Signature
123
- #
124
- # * *Parameters:*
125
- # - +s+ (::String) The string to be mapped
126
- # - +option_strings+ ([::String]) An array of strings against which the mapping will be performed
127
- # - +options+ (Hash) Options that control the behaviour of the method
128
- def self.map_option_string_from_string s, option_strings, options = {}
129
-
130
- MapOptionString_Helper_.map_option_string_with_options_ s, option_strings, options
131
- end
132
-
133
- # Attempts to translate the (string) value of the receiver according
134
- # to a collection of options strings
135
- #
136
- # === Signature
137
- #
138
- # * *Parameters:*
139
- # - +option_strings+ ([::String]) An array of strings against which the mapping will be performed
140
- def map_option_string option_strings, options = {}
115
+ public
116
+
117
+ # Attempts to translate the value of a given string according
118
+ # to a collection of options strings
119
+ #
120
+ # === Signature
121
+ #
122
+ # * *Parameters:*
123
+ # - +s+ (+String+) The string to be mapped;
124
+ # - +option_strings+ (+[ String ]+) An array of strings against which the mapping will be performed;
125
+ # - +options+ (+Hash+) Options that control the behaviour of the method;
126
+ def self.map_option_string_from_string s, option_strings, options = {}
127
+
128
+ MapOptionString_Helper_.map_option_string_with_options_ s, option_strings, options
129
+ end
141
130
 
142
- s = self.kind_of?(::String) ? self : self.to_str
131
+ # Attempts to translate the (string) value of the receiver according
132
+ # to a collection of options strings
133
+ #
134
+ # === Signature
135
+ #
136
+ # * *Parameters:*
137
+ # - +option_strings+ (+[ String ]+) An array of strings against which the mapping will be performed;
138
+ def map_option_string option_strings, options = {}
143
139
 
144
- MapOptionString_Helper_.map_option_string_with_options_ s, option_strings, options
145
- end
146
- end # module MapOptionString
140
+ s = self.kind_of?(::String) ? self : self.to_str
147
141
 
142
+ MapOptionString_Helper_.map_option_string_with_options_ s, option_strings, options
143
+ end
144
+ end # module MapOptionString
148
145
  end # module CommandLineUtilities
149
146
  end # module Xqsr3
150
147