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.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/examples/count_word_frequencies.md +13 -13
- data/examples/count_word_frequencies.rb +5 -5
- data/lib/xqsr3/array_utilities/join_with_or.rb +53 -54
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -67
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +405 -404
- data/lib/xqsr3/containers/multi_map.rb +454 -453
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +56 -57
- data/lib/xqsr3/conversion/integer_parser.rb +92 -93
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +152 -151
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +99 -95
- data/lib/xqsr3/diagnostics/inspect_builder.rb +86 -86
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +136 -136
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +18 -17
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +41 -41
- data/lib/xqsr3/extensions/enumerable/unique.rb +32 -31
- 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 +34 -34
- data/lib/xqsr3/extensions/kernel/integer.rb +26 -26
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +15 -14
- 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 -5
- 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 -2
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -9
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -2
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +7 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -62
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +7 -8
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +6 -7
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +36 -38
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +71 -71
- data/lib/xqsr3/hash_utilities/key_matching.rb +82 -82
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +130 -88
- data/lib/xqsr3/io/writelines.rb +125 -125
- data/lib/xqsr3/quality/parameter_checking.rb +452 -453
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +64 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +33 -34
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +35 -35
- data/lib/xqsr3/string_utilities/quote_if.rb +55 -56
- data/lib/xqsr3/string_utilities/starts_with.rb +64 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +80 -80
- data/lib/xqsr3/string_utilities/truncate.rb +60 -61
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +19 -20
- data/test/performance/frequency_map.rb +13 -27
- data/test/scratch/test_assert_raise_with_message.rb +12 -13
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -142
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +607 -554
- data/test/unit/containers/tc_multi_map.rb +573 -522
- data/test/unit/conversion/tc_integer_parser.rb +73 -73
- data/test/unit/conversion/tc_to_bool.rb +26 -26
- 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_hash.rb +1 -1
- data/test/unit/extensions/hash/tc_slice.rb +14 -14
- 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 +77 -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 +51 -51
- 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 +106 -108
- data/test/unit/quality/tc_parameter_checking.rb +390 -390
- data/test/unit/string_utilities/tc_truncate.rb +28 -28
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/string_utilities/starts_with.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
6
|
-
# module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::StartsWith module
|
7
6
|
#
|
8
|
-
# Created:
|
9
|
-
# Updated:
|
7
|
+
# Created: 13th April 2016
|
8
|
+
# Updated: 29th March 2024
|
10
9
|
#
|
11
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
12
11
|
#
|
13
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
14
13
|
#
|
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
|
#
|
@@ -26,7 +26,7 @@
|
|
26
26
|
# notice, this list of conditions and the following disclaimer in the
|
27
27
|
# documentation and/or other materials provided with the distribution.
|
28
28
|
#
|
29
|
-
# * Neither the names of the copyright
|
29
|
+
# * Neither the names of the copyright holders nor the names of its
|
30
30
|
# contributors may be used to endorse or promote products derived from
|
31
31
|
# this software without specific prior written permission.
|
32
32
|
#
|
@@ -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
|
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/string_utilities/to_symbol.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
6
|
-
# module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::ToSymbol module
|
7
6
|
#
|
8
|
-
# Created:
|
9
|
-
# Updated:
|
7
|
+
# Created: 14th April 2016
|
8
|
+
# Updated: 29th March 2024
|
10
9
|
#
|
11
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
12
11
|
#
|
13
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
14
13
|
#
|
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
|
#
|
@@ -26,7 +26,7 @@
|
|
26
26
|
# notice, this list of conditions and the following disclaimer in the
|
27
27
|
# documentation and/or other materials provided with the distribution.
|
28
28
|
#
|
29
|
-
# * Neither the names of the copyright
|
29
|
+
# * Neither the names of the copyright holders nor the names of its
|
30
30
|
# contributors may be used to endorse or promote products derived from
|
31
31
|
# this software without specific prior written permission.
|
32
32
|
#
|
@@ -58,103 +58,103 @@ module StringUtilities
|
|
58
58
|
#
|
59
59
|
module ToSymbol
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
private
|
62
|
+
# @!visibility private
|
63
|
+
module ToSymbol_Helper_ # :nodoc: all
|
64
64
|
|
65
|
-
|
65
|
+
module Constants # :nodoc:
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
SymbolCharacters0 = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
68
|
+
SymbolCharactersN = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'
|
69
|
+
end
|
70
70
|
|
71
|
-
|
71
|
+
def self.string_to_symbol_with_options_ s, options # :nodoc:
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
case s
|
74
|
+
when ::String
|
75
|
+
;
|
76
|
+
else
|
77
77
|
|
78
|
-
|
78
|
+
if s.respond_to? :to_str
|
79
79
|
|
80
|
-
|
81
|
-
|
80
|
+
s = s.to_str
|
81
|
+
else
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
raise TypeError, "string argument must be of type #{::String} or a type that will respond to to_str"
|
84
|
+
end
|
85
|
+
end
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
case options
|
88
|
+
when ::Hash
|
89
|
+
;
|
90
|
+
else
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
raise TypeError, "options must be of type #{::Hash}, #{options.class} given"
|
93
|
+
end
|
94
94
|
|
95
|
-
|
95
|
+
return nil if s.empty?
|
96
96
|
|
97
|
-
|
97
|
+
transform_characters = options[:transform_characters] || []
|
98
98
|
|
99
|
-
|
99
|
+
s.chars.map.with_index do |c, index|
|
100
100
|
|
101
|
-
|
101
|
+
if 0 != index && Constants::SymbolCharactersN.include?(c)
|
102
102
|
|
103
|
-
|
104
|
-
|
103
|
+
c
|
104
|
+
elsif 0 == index && Constants::SymbolCharacters0.include?(c)
|
105
105
|
|
106
|
-
|
107
|
-
|
106
|
+
c
|
107
|
+
else
|
108
108
|
|
109
|
-
|
110
|
-
|
109
|
+
case c
|
110
|
+
when '-'
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
return nil if options[:reject_hyphens]
|
113
|
+
when ' '
|
114
114
|
|
115
|
-
|
116
|
-
|
115
|
+
return nil if options[:reject_spaces] || options[:reject_whitespace]
|
116
|
+
when ?\t
|
117
117
|
|
118
|
-
|
119
|
-
|
118
|
+
return nil if options[:reject_tabs] || options[:reject_whitespace]
|
119
|
+
else
|
120
120
|
|
121
|
-
|
122
|
-
|
121
|
+
return nil unless transform_characters.include? c
|
122
|
+
end
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
124
|
+
'_'
|
125
|
+
end
|
126
|
+
end.join('').to_sym
|
127
|
+
end
|
128
|
+
end
|
129
|
+
public
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
131
|
+
# Converts the given string +s+ to a symbol according to the given
|
132
|
+
# +options+
|
133
|
+
#
|
134
|
+
# === Signature
|
135
|
+
#
|
136
|
+
# * *Parameters:*
|
137
|
+
# - +s+ (String) The string to convert
|
138
|
+
# - +options+ (Hash) Options hash
|
139
|
+
#
|
140
|
+
# * *Options:*
|
141
|
+
# - +:reject_hyphens+ (boolean)
|
142
|
+
# - +:reject_spaces+ (boolean)
|
143
|
+
# - +:reject_tabs+ (boolean)
|
144
|
+
# - +:reject_whitespace+ (boolean)
|
145
|
+
# - +:transform_characters+ (boolean)
|
146
|
+
def self.string_to_symbol s, options = {}
|
147
147
|
|
148
|
-
|
149
|
-
|
148
|
+
ToSymbol_Helper_.string_to_symbol_with_options_ s, options
|
149
|
+
end
|
150
150
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
151
|
+
# Converts the instance to a symbol, according to the given +options+
|
152
|
+
#
|
153
|
+
# See Xqsr3::StringUtilities::ToSymbol::string_to_symbol for options
|
154
|
+
def to_symbol options = {}
|
155
155
|
|
156
|
-
|
157
|
-
|
156
|
+
ToSymbol_Helper_.string_to_symbol_with_options_ self, options
|
157
|
+
end
|
158
158
|
end # module ToSymbol
|
159
159
|
|
160
160
|
end # module StringUtilities
|
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/string_utilities/truncate.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
6
|
-
# module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::StringUtilities::Truncate module
|
7
6
|
#
|
8
|
-
# Created:
|
9
|
-
# Updated:
|
7
|
+
# Created: 12th April 2018
|
8
|
+
# Updated: 29th March 2024
|
10
9
|
#
|
11
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
12
11
|
#
|
13
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
14
13
|
#
|
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
|
#
|
@@ -26,7 +26,7 @@
|
|
26
26
|
# notice, this list of conditions and the following disclaimer in the
|
27
27
|
# documentation and/or other materials provided with the distribution.
|
28
28
|
#
|
29
|
-
# * Neither the names of the copyright
|
29
|
+
# * Neither the names of the copyright holders nor the names of its
|
30
30
|
# contributors may be used to endorse or promote products derived from
|
31
31
|
# this software without specific prior written permission.
|
32
32
|
#
|
@@ -58,75 +58,75 @@ module StringUtilities
|
|
58
58
|
#
|
59
59
|
module Truncate
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
private
|
62
|
+
# @!visibility private
|
63
|
+
module Truncate_Helper_ # :nodoc: all
|
64
64
|
|
65
|
-
|
65
|
+
def self.string_truncate_with_options_ s, width, options # :nodoc:
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
case s
|
68
|
+
when ::String
|
69
|
+
;
|
70
|
+
else
|
71
71
|
|
72
|
-
|
72
|
+
if s.respond_to? :to_str
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
s = s.to_str
|
75
|
+
else
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
raise TypeError, "string argument must be of type #{::String} or a type that will respond to to_str"
|
78
|
+
end
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
case options
|
82
|
+
when ::Hash
|
83
|
+
;
|
84
|
+
else
|
85
85
|
|
86
|
-
|
87
|
-
|
86
|
+
raise TypeError, "options must be of type #{::Hash}, #{options.class} given"
|
87
|
+
end
|
88
88
|
|
89
|
-
|
89
|
+
len = s.size
|
90
90
|
|
91
|
-
|
91
|
+
return s if len <= width
|
92
92
|
|
93
|
-
|
93
|
+
omission = options[:omission] || '...'
|
94
94
|
|
95
|
-
|
95
|
+
if width < omission.size
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
return omission[0...width]
|
98
|
+
else
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
return s[0...(width - omission.size)] + omission
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
public
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
106
|
+
# Truncates the given string +s+ to the given +width+ according to the
|
107
|
+
# given +options+
|
108
|
+
#
|
109
|
+
# === Signature
|
110
|
+
#
|
111
|
+
# * *Parameters:*
|
112
|
+
# - +s+ (String) The string to convert
|
113
|
+
# - +width+ (Integer) The truncation width
|
114
|
+
# - +options+ (Hash) Options hash
|
115
|
+
#
|
116
|
+
# * *Options:*
|
117
|
+
# - +:omission+ (String) Omission string. Defaults to "..."
|
118
|
+
def self.string_truncate s, width, options = {}
|
119
119
|
|
120
|
-
|
121
|
-
|
120
|
+
Truncate_Helper_.string_truncate_with_options_ s, width, options
|
121
|
+
end
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
# Truncates the instance, according to the given +width+ and +options+
|
124
|
+
#
|
125
|
+
# See Xqsr3::StringUtilities::ToSymbol::string_truncate for options
|
126
|
+
def truncate width, options = {}
|
127
127
|
|
128
|
-
|
129
|
-
|
128
|
+
Truncate_Helper_.string_truncate_with_options_ self, width, options
|
129
|
+
end
|
130
130
|
end # module Truncate
|
131
131
|
|
132
132
|
end # module StringUtilities
|
@@ -134,4 +134,3 @@ end # module Xqsr3
|
|
134
134
|
|
135
135
|
# ############################## end of file ############################# #
|
136
136
|
|
137
|
-
|
@@ -1,16 +1,16 @@
|
|
1
1
|
|
2
2
|
%w{
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
ends_with
|
5
|
+
nil_if_empty
|
6
|
+
nil_if_whitespace
|
7
|
+
quote_if
|
8
|
+
starts_with
|
9
|
+
to_symbol
|
10
|
+
truncate
|
11
11
|
}.each do |name|
|
12
12
|
|
13
|
-
|
13
|
+
require File.join(File.dirname(__FILE__), 'string_utilities', name)
|
14
14
|
end
|
15
15
|
|
16
16
|
|
data/lib/xqsr3/version.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: lib/xqsr3/version.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Version for Xqsr3 library
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 3rd April 2016
|
8
|
+
# Updated: 30th March 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
12
|
-
# Author:
|
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
|
#
|
@@ -26,7 +26,7 @@
|
|
26
26
|
# notice, this list of conditions and the following disclaimer in the
|
27
27
|
# documentation and/or other materials provided with the distribution.
|
28
28
|
#
|
29
|
-
# * Neither the names of the copyright
|
29
|
+
# * Neither the names of the copyright holders nor the names of its
|
30
30
|
# contributors may be used to endorse or promote products derived from
|
31
31
|
# this software without specific prior written permission.
|
32
32
|
#
|
@@ -50,21 +50,20 @@
|
|
50
50
|
|
51
51
|
module Xqsr3
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
# Current version of the Xqsr3 library
|
54
|
+
VERSION = '0.39.1'
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
56
|
+
private
|
57
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
58
|
+
public
|
59
|
+
# Major version of the Xqsr3 library
|
60
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
61
|
+
# Minor version of the Xqsr3 library
|
62
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
63
|
+
# Revision version of the Xqsr3 library
|
64
|
+
VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
|
65
65
|
|
66
66
|
end # module Xqsr3
|
67
67
|
|
68
68
|
# ############################## end of file ############################# #
|
69
69
|
|
70
|
-
|