xqsr3 0.39.1 → 0.39.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/count_word_frequencies.rb +2 -0
- data/lib/xqsr3/array_utilities/join_with_or.rb +50 -53
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -69
- data/lib/xqsr3/containers/frequency_map.rb +408 -394
- data/lib/xqsr3/containers/multi_map.rb +464 -446
- data/lib/xqsr3/conversion/bool_parser.rb +49 -54
- data/lib/xqsr3/conversion/integer_parser.rb +84 -89
- data/lib/xqsr3/diagnostics/exception_utilities.rb +127 -132
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +98 -102
- data/lib/xqsr3/diagnostics/inspect_builder.rb +83 -84
- data/lib/xqsr3/extensions/array/join_with_or.rb +2 -1
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +1 -4
- data/lib/xqsr3/extensions/enumerable/unique.rb +1 -4
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -0
- data/lib/xqsr3/extensions/hash/except.rb +1 -1
- data/lib/xqsr3/extensions/hash/has_match.rb +3 -2
- data/lib/xqsr3/extensions/hash/match.rb +3 -2
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +1 -4
- data/lib/xqsr3/extensions/io/writelines.rb +4 -7
- data/lib/xqsr3/extensions/kernel/integer.rb +7 -9
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +1 -3
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -0
- data/lib/xqsr3/extensions/string/map_option_string.rb +1 -0
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -0
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -0
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -0
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -0
- data/lib/xqsr3/extensions/string/to_bool.rb +1 -0
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -0
- data/lib/xqsr3/extensions/string/truncate.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +58 -55
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -37
- data/lib/xqsr3/hash_utilities/deep_transform.rb +63 -67
- data/lib/xqsr3/hash_utilities/key_matching.rb +72 -76
- data/lib/xqsr3/internal_/test_unit_version_.rb +10 -8
- data/lib/xqsr3/io/writelines.rb +12 -12
- data/lib/xqsr3/quality/parameter_checking.rb +406 -411
- data/lib/xqsr3/string_utilities/ends_with.rb +60 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +31 -35
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +32 -36
- data/lib/xqsr3/string_utilities/quote_if.rb +48 -57
- data/lib/xqsr3/string_utilities/starts_with.rb +60 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +77 -81
- data/lib/xqsr3/string_utilities/truncate.rb +56 -60
- data/lib/xqsr3/version.rb +2 -2
- data/test/performance/frequency_map.rb +3 -0
- data/test/scratch/test_assert_raise_with_message.rb +2 -0
- data/test/unit/array_utilities/tc_join_with_or.rb +3 -1
- data/test/unit/command_line_utilities/tc_map_option_string.rb +3 -0
- data/test/unit/containers/tc_frequency_map.rb +5 -2
- data/test/unit/containers/tc_multi_map.rb +3 -0
- data/test/unit/conversion/tc_integer_parser.rb +18 -17
- data/test/unit/conversion/tc_to_bool.rb +2 -0
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +7 -5
- data/test/unit/diagnostics/tc_exception_utilities.rb +2 -0
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +2 -0
- data/test/unit/extensions/enumerable/tc_detect_map.rb +3 -2
- data/test/unit/extensions/enumerable/tc_unique.rb +2 -0
- data/test/unit/extensions/hash/tc_deep_transform.rb +2 -0
- data/test/unit/extensions/hash/tc_except.rb +3 -1
- data/test/unit/extensions/hash/tc_hash.rb +1 -0
- data/test/unit/extensions/hash/tc_slice.rb +2 -0
- data/test/unit/extensions/integer/tc_to_s_grp.rb +2 -0
- data/test/unit/extensions/io/tc_writelines.rb +86 -0
- data/test/unit/extensions/kernel/tc_integer.rb +10 -9
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +2 -0
- data/test/unit/extensions/object/tc_inspect.rb +15 -13
- data/test/unit/extensions/string/tc_bool.tb +2 -0
- data/test/unit/extensions/string/tc_ends_with.rb +2 -0
- data/test/unit/extensions/string/tc_map_option_string.rb +2 -0
- data/test/unit/extensions/string/tc_nil_if_empty.rb +2 -0
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +2 -0
- data/test/unit/extensions/string/tc_quote_if.rb +2 -0
- data/test/unit/extensions/string/tc_starts_with.rb +2 -0
- data/test/unit/extensions/string/tc_to_symbol.rb +2 -0
- data/test/unit/extensions/string/tc_truncate.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +2 -0
- data/test/unit/hash_utilities/tc_has_match.rb +1 -0
- data/test/unit/hash_utilities/tc_match.rb +1 -0
- data/test/unit/io/tc_writelines.rb +63 -0
- data/test/unit/quality/tc_parameter_checking.rb +1 -0
- data/test/unit/string_utilities/tc_truncate.rb +2 -0
- data/test/unit/tc_version.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e7be3a60a6d9752fee2e9923806d69cec535c99ecce3c3207497e4df761735
|
4
|
+
data.tar.gz: d1be5a5d287f913bd5f4396f2ecfc32b06185e7ab64f4a4748500c4f47249932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdaaf454c457db16d69d8ecba4923fa16afeb2d01dfec6eab300d53d38907d21559b845e87605c901f9a76982b12567bc8ecfe765aef7d4a42c490bce0ba9cf1
|
7
|
+
data.tar.gz: fc31c9538d65af1747b3f8e51a8cb81a9beb45bce9a5170b71da3a603611ec99672ee5efe71b498b242738d8092f02353542ea4f98ab870f721d7616324a2668
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Definition of the ::Xqsr3::ArrayUtilities::JoinWithOr module
|
6
6
|
#
|
7
7
|
# Created: 7th December 2017
|
8
|
-
# Updated:
|
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
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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:
|
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
|
-
|
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
|
-
|
70
|
-
|
70
|
+
private
|
71
|
+
# @!visibility private
|
72
|
+
module MapOptionString_Helper_ # :nodoc: all
|
71
73
|
|
72
|
-
|
73
|
-
# @!visibility private
|
74
|
-
module MapOptionString_Helper_ # :nodoc: all
|
74
|
+
def self.map_option_string_with_options_ s, option_strings, options
|
75
75
|
|
76
|
-
|
76
|
+
h = {}
|
77
77
|
|
78
|
-
|
78
|
+
option_strings.each do |os|
|
79
79
|
|
80
|
-
|
80
|
+
t = os.dup
|
81
|
+
v = os.dup
|
81
82
|
|
82
|
-
|
83
|
-
v = os.dup
|
83
|
+
if t =~ /\[.+?\]/
|
84
84
|
|
85
|
-
|
85
|
+
k = ''
|
86
|
+
v = ''
|
86
87
|
|
87
|
-
|
88
|
-
v = ''
|
88
|
+
while t =~ /\[(.+?)\]/
|
89
89
|
|
90
|
-
|
90
|
+
k += $1
|
91
|
+
v += "#$`#$1"
|
92
|
+
t = $'
|
93
|
+
end
|
91
94
|
|
92
|
-
|
93
|
-
|
94
|
-
t = $'
|
95
|
-
end
|
95
|
+
v += t
|
96
|
+
else
|
96
97
|
|
97
|
-
|
98
|
-
|
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[
|
104
|
-
h[v] = v
|
105
|
-
end
|
105
|
+
r = h[s]
|
106
106
|
|
107
|
-
|
107
|
+
if r
|
108
108
|
|
109
|
-
|
109
|
+
r = ::Xqsr3::StringUtilities::ToSymbol.string_to_symbol r
|
110
|
+
end
|
110
111
|
|
111
|
-
r
|
112
|
+
r
|
112
113
|
end
|
113
|
-
|
114
|
-
r
|
115
114
|
end
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
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
|
-
|
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
|
|