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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9ed73f4599f60f4dfbbd40d39d1967cccdf74e69b5f317d859128f04777551c
|
4
|
+
data.tar.gz: 07b8984f99e23d99ce1fd1cd05fc5b553ddb587e732d8b6d0deac758c95644f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b78b409d39d78d7e8fc44a31db077e8638d64f91545212ad2ed2921b4a39a5f2d1fc266ffb71ed16b7fb3fd48f947923135144401144942774e93a61938715d3
|
7
|
+
data.tar.gz: a0b0e40fcc75a20cf3f2203920c807819b88270ae1e4cb987166243e829a05a9d1288b7cc1e2923f3895504cf83272cdb89de92be5b053705dcb04be9c63c492
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# xqsr3
|
1
|
+
# xqsr3 <!-- omit in toc -->
|
2
|
+
|
2
3
|
e**X**tensions by fine **Q**uantum for **S**tandard **R**uby and **3**rd-party libraries
|
3
4
|
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/xqsr3.svg)](https://badge.fury.io/rb/xqsr3)
|
@@ -11,12 +12,17 @@ It has **no dependencies** on any other non-standard library.
|
|
11
12
|
|
12
13
|
It may be pronounced (lamely) as "excusers".
|
13
14
|
|
14
|
-
## Table of Contents
|
15
|
+
## Table of Contents <!-- omit in toc -->
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
- [Introduction](#introduction)
|
18
|
+
- [Installation](#installation)
|
19
|
+
- [Components](#components)
|
20
|
+
- [Examples](#examples)
|
21
|
+
- [Project Information](#project-information)
|
22
|
+
- [Where to get help](#where-to-get-help)
|
23
|
+
- [Contribution guidelines](#contribution-guidelines)
|
24
|
+
- [Related projects](#related-projects)
|
25
|
+
- [License](#license)
|
20
26
|
|
21
27
|
## Installation
|
22
28
|
|
@@ -104,3 +110,6 @@ and a development dependency of:
|
|
104
110
|
|
105
111
|
**xqsr3** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
|
106
112
|
|
113
|
+
|
114
|
+
<!-- ########################### end of file ########################### -->
|
115
|
+
|
@@ -32,9 +32,9 @@ words.each { |word| fm << word }
|
|
32
32
|
|
33
33
|
fm.each_by_frequency do |word, frequency|
|
34
34
|
|
35
|
-
|
35
|
+
next if 1 == frequency
|
36
36
|
|
37
|
-
|
37
|
+
$stdout.puts "\t#{word}\t#{frequency}"
|
38
38
|
end
|
39
39
|
puts
|
40
40
|
|
@@ -45,9 +45,9 @@ fm = FrequencyMap::ByElement[*words]
|
|
45
45
|
|
46
46
|
fm.each_by_frequency do |word, frequency|
|
47
47
|
|
48
|
-
|
48
|
+
next if 1 == frequency
|
49
49
|
|
50
|
-
|
50
|
+
$stdout.puts "\t#{word}\t#{frequency}"
|
51
51
|
end
|
52
52
|
puts
|
53
53
|
|
@@ -67,16 +67,16 @@ When run, this produces the following output:
|
|
67
67
|
Analyse DATA words via FrequencyMap
|
68
68
|
|
69
69
|
1. Manually (showing items with 2+ occurrences):
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
in 3
|
71
|
+
dolor 2
|
72
|
+
dolore 2
|
73
|
+
ut 2
|
74
74
|
|
75
75
|
2. Via ByElement (showing items with 2+ occurrences):
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
in 3
|
77
|
+
dolor 2
|
78
|
+
dolore 2
|
79
|
+
ut 2
|
80
80
|
```
|
81
81
|
|
82
82
|
|
@@ -23,9 +23,9 @@ words.each { |word| fm << word }
|
|
23
23
|
|
24
24
|
fm.each_by_frequency do |word, frequency|
|
25
25
|
|
26
|
-
|
26
|
+
next if 1 == frequency
|
27
27
|
|
28
|
-
|
28
|
+
$stdout.puts "\t#{word}\t#{frequency}"
|
29
29
|
end
|
30
30
|
puts
|
31
31
|
|
@@ -36,9 +36,9 @@ fm = FrequencyMap::ByElement[*words]
|
|
36
36
|
|
37
37
|
fm.each_by_frequency do |word, frequency|
|
38
38
|
|
39
|
-
|
39
|
+
next if 1 == frequency
|
40
40
|
|
41
|
-
|
41
|
+
$stdout.puts "\t#{word}\t#{frequency}"
|
42
42
|
end
|
43
43
|
puts
|
44
44
|
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/array_utilities/join_with_or.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::ArrayUtilities::JoinWithOr module
|
5
|
+
# Purpose: Definition of the ::Xqsr3::ArrayUtilities::JoinWithOr module
|
6
6
|
#
|
7
7
|
# Created: 7th December 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
|
#
|
@@ -59,50 +59,50 @@ module ArrayUtilities
|
|
59
59
|
# +include+-able module that provides sequence-joining functionality
|
60
60
|
module JoinWithOr
|
61
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
|
-
|
104
|
-
|
105
|
-
|
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]}"
|
104
|
+
end
|
105
|
+
end
|
106
106
|
|
107
107
|
end # module JoinWithOr
|
108
108
|
|
@@ -2,17 +2,17 @@
|
|
2
2
|
# ######################################################################## #
|
3
3
|
# File: lib/xqsr3/command_line_utilities/map_option_string.rb
|
4
4
|
#
|
5
|
-
# Purpose: Definition of the Xqsr3::CommandLineUtilities::MapOptionString
|
5
|
+
# Purpose: Definition of the ::Xqsr3::CommandLineUtilities::MapOptionString
|
6
6
|
# module
|
7
7
|
#
|
8
8
|
# Created: 15th April 2016
|
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) 2016-2019, Matthew Wilson and Synesis Software
|
17
17
|
# All rights reserved.
|
18
18
|
#
|
@@ -64,85 +64,85 @@ module CommandLineUtilities
|
|
64
64
|
# * ::Xqsr3::CommandLineUtilities::MapOptionString#map_option_string
|
65
65
|
module MapOptionString
|
66
66
|
|
67
|
-
|
67
|
+
def self.included includer # :nodoc:
|
68
68
|
|
69
|
-
|
70
|
-
|
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
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
private
|
73
|
+
# @!visibility private
|
74
|
+
module MapOptionString_Helper_ # :nodoc: all
|
75
75
|
|
76
|
-
|
76
|
+
def self.map_option_string_with_options_ s, option_strings, options
|
77
77
|
|
78
|
-
|
78
|
+
h = {}
|
79
79
|
|
80
|
-
|
80
|
+
option_strings.each do |os|
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
t = os.dup
|
83
|
+
v = os.dup
|
84
84
|
|
85
|
-
|
85
|
+
if t =~ /\[.+?\]/
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
k = ''
|
88
|
+
v = ''
|
89
89
|
|
90
|
-
|
90
|
+
while t =~ /\[(.+?)\]/
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
k += $1
|
93
|
+
v += "#$`#$1"
|
94
|
+
t = $'
|
95
|
+
end
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
v += t
|
98
|
+
else
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
k = v
|
101
|
+
end
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
h[k] = v
|
104
|
+
h[v] = v
|
105
|
+
end
|
106
106
|
|
107
|
-
|
107
|
+
r = h[s]
|
108
108
|
|
109
|
-
|
109
|
+
if r
|
110
110
|
|
111
|
-
|
112
|
-
|
111
|
+
r = ::Xqsr3::StringUtilities::ToSymbol.string_to_symbol r
|
112
|
+
end
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
r
|
115
|
+
end
|
116
|
+
end
|
117
|
+
public
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
129
|
|
130
|
-
|
131
|
-
|
130
|
+
MapOptionString_Helper_.map_option_string_with_options_ s, option_strings, options
|
131
|
+
end
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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 = {}
|
141
141
|
|
142
|
-
|
142
|
+
s = self.kind_of?(::String) ? self : self.to_str
|
143
143
|
|
144
|
-
|
145
|
-
|
144
|
+
MapOptionString_Helper_.map_option_string_with_options_ s, option_strings, options
|
145
|
+
end
|
146
146
|
end # module MapOptionString
|
147
147
|
|
148
148
|
end # module CommandLineUtilities
|