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
data/lib/xqsr3/quality.rb
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/string_utilities/ends_with.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::StringUtilities::EndsWith module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::EndsWith module
|
6
6
|
#
|
7
7
|
# Created: 13th April 2016
|
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) 2016-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -58,84 +58,84 @@ module StringUtilities
|
|
58
58
|
# methods
|
59
59
|
module EndsWith
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
private
|
62
|
+
# @!visibility private
|
63
|
+
module EndsWith_Helper_ # :nodoc: all
|
64
64
|
|
65
|
-
|
65
|
+
def self.string_ends_with_helper_ s, prefix # :nodoc:
|
66
66
|
|
67
|
-
|
67
|
+
if prefix.nil? || prefix.empty?
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
return ''
|
70
|
+
elsif prefix.size < s.size
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
return prefix if s[(s.size - prefix.size) ... s.size] == prefix
|
73
|
+
elsif prefix.size == s.size
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
return prefix if prefix == s
|
76
|
+
else
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
nil
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
nil
|
82
|
+
end
|
83
83
|
|
84
|
-
|
84
|
+
def self.string_ends_with_array_ s, args # :nodoc:
|
85
85
|
|
86
|
-
|
86
|
+
return '' if args.empty?
|
87
87
|
|
88
|
-
|
88
|
+
args.each do |prefix|
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
case prefix
|
91
|
+
when ::NilClass
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
return ''
|
94
|
+
when ::String
|
95
95
|
|
96
|
-
|
96
|
+
r = self.string_ends_with_helper_ s, prefix
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
return r if r
|
99
|
+
else
|
100
100
|
|
101
|
-
|
101
|
+
if prefix.respond_to? :to_str
|
102
102
|
|
103
|
-
|
104
|
-
|
103
|
+
return self.string_ends_with_helper_ s.prefix.to_str
|
104
|
+
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
raise TypeError, "ends_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
|
107
|
+
end
|
108
|
+
end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
return nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
public
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
# Reports on whether a string +s+ ends with a given prefix or set of
|
116
|
+
# prefixes (+args+)
|
117
|
+
#
|
118
|
+
# === Signature
|
119
|
+
#
|
120
|
+
# * *Parameters:*
|
121
|
+
# - +s+ (String) The string to be evaluated
|
122
|
+
# - +args+ 0+ arguments against which +s+ will be evaluated
|
123
|
+
def self.string_ends_with? s, *args
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
EndsWith_Helper_.string_ends_with_array_ s, args
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
128
|
+
# Reports on whether the instance ends with a given prefix or set of
|
129
|
+
# prefixes (+args+)
|
130
|
+
#
|
131
|
+
# === Signature
|
132
|
+
#
|
133
|
+
# * *Parameters:*
|
134
|
+
# - +args+ 0+ arguments against which the instance will be evaluated
|
135
|
+
def ends_with? *args
|
136
136
|
|
137
|
-
|
138
|
-
|
137
|
+
EndsWith_Helper_.string_ends_with_array_ self, args
|
138
|
+
end
|
139
139
|
end # module EndsWith
|
140
140
|
|
141
141
|
end # module StringUtilities
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/string_utilities/nil_if_empty.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::StringUtilities::NilIfEmpty module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::NilIfEmpty module
|
6
6
|
#
|
7
7
|
# Created: 25th January 2018
|
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) 2018-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -58,38 +58,38 @@ module StringUtilities
|
|
58
58
|
# #nil_if_empty methods
|
59
59
|
module NilIfEmpty
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
private
|
62
|
+
# @!visibility private
|
63
|
+
module NilIfEmpty_Helper_ # :nodoc: all
|
64
64
|
|
65
|
-
|
65
|
+
def self.string_nil_if_empty_array_ s # :nodoc:
|
66
66
|
|
67
|
-
|
67
|
+
return s if s && !s.empty?
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
public
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
74
|
+
# Returns +nil+ if the given string is empty, otherwise returning the
|
75
|
+
# given string
|
76
|
+
#
|
77
|
+
# === Signature
|
78
|
+
#
|
79
|
+
# * *Parameters:*
|
80
|
+
#
|
81
|
+
# * *Required parameters*:
|
82
|
+
# - +s+ (String) The string to be evaluated
|
83
|
+
def self.string_nil_if_empty s
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
NilIfEmpty_Helper_.string_nil_if_empty_array_ s
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
# Returns +nil+ if the instance is empty, otherwise returning self
|
89
|
+
def nil_if_empty
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
NilIfEmpty_Helper_.string_nil_if_empty_array_ self
|
92
|
+
end
|
93
93
|
end # module NilIfEmpty
|
94
94
|
|
95
95
|
end # module StringUtilities
|
@@ -2,17 +2,17 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/string_utilities/nil_if_whitespace.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::StringUtilities::NilIfWhitespace
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::NilIfWhitespace
|
6
6
|
# module
|
7
7
|
#
|
8
8
|
# Created: 25th January 2018
|
9
|
-
# Updated:
|
9
|
+
# Updated: 29th March 2024
|
10
10
|
#
|
11
11
|
# Home: http://github.com/synesissoftware/xqsr3
|
12
12
|
#
|
13
13
|
# Author: Matthew Wilson
|
14
14
|
#
|
15
|
-
# Copyright (c) 2019-
|
15
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
16
16
|
# Copyright (c) 2018-2019, Matthew Wilson and Synesis Software
|
17
17
|
# All rights reserved.
|
18
18
|
#
|
@@ -59,39 +59,39 @@ module StringUtilities
|
|
59
59
|
# #nil_if_whitespace methods
|
60
60
|
module NilIfWhitespace
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
private
|
63
|
+
# @!visibility private
|
64
|
+
module NilIfWhitespace_Helper_ # :nodoc: all
|
65
65
|
|
66
|
-
|
66
|
+
def self.string_nil_if_whitespace_array_ s # :nodoc:
|
67
67
|
|
68
|
-
|
68
|
+
return nil if s.strip.empty?
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
s
|
71
|
+
end
|
72
|
+
end
|
73
|
+
public
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
75
|
+
# Returns +nil+ if the given string is empty or contains only whitespace,
|
76
|
+
# otherwise returning the given string
|
77
|
+
#
|
78
|
+
# === Signature
|
79
|
+
#
|
80
|
+
# * *Parameters:*
|
81
|
+
#
|
82
|
+
# * *Required parameters*:
|
83
|
+
# - +s+ (String) The string to be evaluated
|
84
|
+
def self.string_nil_if_whitespace s
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ s
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
# Returns +nil+ if the instance is empty or contains only whitespace,
|
90
|
+
# otherwise returning self
|
91
|
+
def nil_if_whitespace
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ self
|
94
|
+
end
|
95
95
|
end # module NilIfWhitespace
|
96
96
|
|
97
97
|
end # module StringUtilities
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/string_utilities/quote_if.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::StringUtilities::QuoteIf module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::QuoteIf module
|
6
6
|
#
|
7
7
|
# Created: 3rd June 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
|
#
|
@@ -57,67 +57,67 @@ module StringUtilities
|
|
57
57
|
# +include+-able module that provides ::quote_if and #quote_if methods
|
58
58
|
module QuoteIf
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
private
|
61
|
+
# @!visibility private
|
62
|
+
module QuoteIf_Helper_ # :nodoc: all
|
63
63
|
|
64
|
-
|
64
|
+
def self.string_quote_if_array_ s, options # :nodoc:
|
65
65
|
|
66
|
-
|
66
|
+
s = s.to_s unless String === s
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
quotes = options[:quotes] || [ '"', '"' ]
|
69
|
+
quotes = [ quotes, quotes ] if String === quotes
|
70
70
|
|
71
|
-
|
71
|
+
quotables = options[:quotables] || /\s/
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
case quotables
|
74
|
+
when ::String
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
return s unless s.include? quotables
|
77
|
+
when ::Array
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
return s unless quotables.any? { |quotable| s.include? quotable }
|
80
|
+
when ::Regexp
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
return s unless s =~ quotables
|
83
|
+
else
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
raise ArgumentError, "Invalid type (#{quotables.class}) specified for quotables parameter"
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
return quotes[0] + s + quotes[1]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
public
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
93
|
+
# Converts a string to a quoted form if necessary
|
94
|
+
#
|
95
|
+
# === Signature
|
96
|
+
#
|
97
|
+
# * *Parameters:*
|
98
|
+
#
|
99
|
+
# * *Required parameters*:
|
100
|
+
# - +s+ (String) The string to be evaluated
|
101
|
+
#
|
102
|
+
# * *Options parameters*:
|
103
|
+
# - +options+ (Hash) Options that control the behaviour of the method
|
104
|
+
#
|
105
|
+
# * *Options:*
|
106
|
+
#
|
107
|
+
# - +:quotes+ (String, Array) A string that is used as the opening and closing quotes, or an array whose first two elements are used as the opening and closing quotes. Defaults to +'"'+
|
108
|
+
# - +:quotables+ (String, Array, Regexp) A string representing the quotable character, or an array containing the quotable characters, or a regular expression that determines by match whether the string should be quoted. Defaults to the regular expression +/\s/+
|
109
|
+
def self.quote_if s, **options
|
110
110
|
|
111
|
-
|
112
|
-
|
111
|
+
QuoteIf_Helper_.string_quote_if_array_ s, options
|
112
|
+
end
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
# Converts the instance to a quoted form if necessary
|
115
|
+
#
|
116
|
+
# See Xqsr3::StringUtilities::QuoteIf::quite_if() for options
|
117
|
+
def quote_if **options
|
118
118
|
|
119
|
-
|
120
|
-
|
119
|
+
QuoteIf_Helper_.string_quote_if_array_ self, options
|
120
|
+
end
|
121
121
|
end # module QuoteIf
|
122
122
|
|
123
123
|
end # module StringUtilities
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/string_utilities/starts_with.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::StringUtilities::StartsWith module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::StartsWith module
|
6
6
|
#
|
7
7
|
# Created: 13th April 2016
|
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) 2016-2019, Matthew Wilson and Synesis Software
|
16
16
|
# All rights reserved.
|
17
17
|
#
|
@@ -58,84 +58,84 @@ module StringUtilities
|
|
58
58
|
# methods
|
59
59
|
module StartsWith
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
private
|
62
|
+
# @!visibility private
|
63
|
+
module StartsWith_Helper_ # :nodoc: all
|
64
64
|
|
65
|
-
|
65
|
+
def self.string_starts_with_helper_ s, prefix # :nodoc:
|
66
66
|
|
67
|
-
|
67
|
+
if prefix.nil? || prefix.empty?
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
return ''
|
70
|
+
elsif prefix.size < s.size
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
return prefix if s[0 ... prefix.size] == prefix
|
73
|
+
elsif prefix.size == s.size
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
return prefix if prefix == s
|
76
|
+
else
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
nil
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
nil
|
82
|
+
end
|
83
83
|
|
84
|
-
|
84
|
+
def self.string_starts_with_array_ s, args # :nodoc:
|
85
85
|
|
86
|
-
|
86
|
+
return '' if args.empty?
|
87
87
|
|
88
|
-
|
88
|
+
args.each do |prefix|
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
case prefix
|
91
|
+
when ::NilClass
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
return ''
|
94
|
+
when ::String
|
95
95
|
|
96
|
-
|
96
|
+
r = self.string_starts_with_helper_ s, prefix
|
97
97
|
|
98
|
-
|
99
|
-
|
98
|
+
return r if r
|
99
|
+
else
|
100
100
|
|
101
|
-
|
101
|
+
if prefix.respond_to? :to_str
|
102
102
|
|
103
|
-
|
104
|
-
|
103
|
+
return self.string_starts_with_helper_ s.prefix.to_str
|
104
|
+
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
raise TypeError, "starts_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
|
107
|
+
end
|
108
|
+
end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
return nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
public
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
# Reports on whether a string +s+ starts with a given prefix or set of
|
116
|
+
# prefixes (+args+)
|
117
|
+
#
|
118
|
+
# === Signature
|
119
|
+
#
|
120
|
+
# * *Parameters:*
|
121
|
+
# - +s+ (String) The string to be evaluated
|
122
|
+
# - +args+ 0+ arguments against which +s+ will be evaluated
|
123
|
+
def self.string_starts_with? s, *args
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
StartsWith_Helper_.string_starts_with_array_ s, args
|
126
|
+
end
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
128
|
+
# Reports on whether the instance starts with a given prefix or set of
|
129
|
+
# prefixes (+args+)
|
130
|
+
#
|
131
|
+
# === Signature
|
132
|
+
#
|
133
|
+
# * *Parameters:*
|
134
|
+
# - +args+ 0+ arguments against which the instance will be evaluated
|
135
|
+
def starts_with? *args
|
136
136
|
|
137
|
-
|
138
|
-
|
137
|
+
StartsWith_Helper_.string_starts_with_array_ self, args
|
138
|
+
end
|
139
139
|
end # module StartsWith
|
140
140
|
|
141
141
|
end # module StringUtilities
|