fat_core 7.3.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -2
- data/.gitignore +1 -1
- data/Gemfile.lock +171 -0
- data/README.md +120 -102
- data/README.org +36 -19
- data/fat_core.gemspec +0 -1
- data/lib/fat_core/string.rb +30 -25
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/string_spec.rb +33 -1
- metadata +4 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f4b84a879ef64ab6054af28511bf9c87975baeef65d006008d4351cbed07be4
|
|
4
|
+
data.tar.gz: 27cc94fe92188194ef68ab18c7dab74e5f80440b321df848b494405c17ea0f46
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4ad4228b75766b03a30719ce23531f60bec37db7753db4153deb21f8eb0b84629346571119b737835be5bd479ed1a0a4e414cafc2f4d3c3630a2fb3a1fa3d64
|
|
7
|
+
data.tar.gz: 7b217c20aa7fa970ea8b44faa85c94692d3307c518bef0f93e2fde59559a220bebadf1cf81649e21e60bb56e43fb2fb8a683633384570868ac1c7b5489035975
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -14,12 +14,15 @@ on:
|
|
|
14
14
|
jobs:
|
|
15
15
|
test:
|
|
16
16
|
runs-on: ubuntu-24.04
|
|
17
|
+
continue-on-error: ${{ matrix.ruby == 'ruby-head' }}
|
|
17
18
|
strategy:
|
|
19
|
+
fail-fast: false
|
|
18
20
|
matrix:
|
|
19
|
-
ruby
|
|
21
|
+
# Minor versions select the latest patch; ruby-head is experimental.
|
|
22
|
+
ruby: ['3.2', '3.3', '3.4', '4.0', 'ruby-head']
|
|
20
23
|
steps:
|
|
21
24
|
- name: Check out code
|
|
22
|
-
uses: actions/checkout@
|
|
25
|
+
uses: actions/checkout@v6
|
|
23
26
|
|
|
24
27
|
- name: Install build dependencies (needed if Ruby must be compiled)
|
|
25
28
|
run: |
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
GIT
|
|
2
|
+
remote: https://github.com/ddoherty03/rubocop-ddoherty.git
|
|
3
|
+
revision: e20a30ef08d9b8ded242cf6b66fa20500c8045c6
|
|
4
|
+
branch: master
|
|
5
|
+
specs:
|
|
6
|
+
rubocop-ddoherty (0.1.3)
|
|
7
|
+
rubocop (~> 1.62)
|
|
8
|
+
rubocop-performance (~> 1.0)
|
|
9
|
+
rubocop-rake (>= 0.7)
|
|
10
|
+
rubocop-rspec (~> 3.0)
|
|
11
|
+
|
|
12
|
+
PATH
|
|
13
|
+
remote: .
|
|
14
|
+
specs:
|
|
15
|
+
fat_core (7.5.0)
|
|
16
|
+
activesupport
|
|
17
|
+
ostruct
|
|
18
|
+
stringio (>= 3.1.2)
|
|
19
|
+
|
|
20
|
+
GEM
|
|
21
|
+
remote: https://rubygems.org/
|
|
22
|
+
specs:
|
|
23
|
+
activesupport (8.1.1)
|
|
24
|
+
base64
|
|
25
|
+
bigdecimal
|
|
26
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
27
|
+
connection_pool (>= 2.2.5)
|
|
28
|
+
drb
|
|
29
|
+
i18n (>= 1.6, < 2)
|
|
30
|
+
json
|
|
31
|
+
logger (>= 1.4.2)
|
|
32
|
+
minitest (>= 5.1)
|
|
33
|
+
securerandom (>= 0.3)
|
|
34
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
35
|
+
uri (>= 0.13.1)
|
|
36
|
+
ast (2.4.3)
|
|
37
|
+
base64 (0.3.0)
|
|
38
|
+
bigdecimal (4.0.1)
|
|
39
|
+
coderay (1.1.3)
|
|
40
|
+
concurrent-ruby (1.3.6)
|
|
41
|
+
connection_pool (3.0.2)
|
|
42
|
+
date (3.5.1)
|
|
43
|
+
debug (1.11.1)
|
|
44
|
+
irb (~> 1.10)
|
|
45
|
+
reline (>= 0.3.8)
|
|
46
|
+
diff-lcs (1.6.2)
|
|
47
|
+
docile (1.4.1)
|
|
48
|
+
drb (2.2.3)
|
|
49
|
+
erb (6.0.1)
|
|
50
|
+
gem_docs (0.4.0)
|
|
51
|
+
rake
|
|
52
|
+
yard (>= 0.9.28)
|
|
53
|
+
i18n (1.14.8)
|
|
54
|
+
concurrent-ruby (~> 1.0)
|
|
55
|
+
io-console (0.8.2)
|
|
56
|
+
irb (1.16.0)
|
|
57
|
+
pp (>= 0.6.0)
|
|
58
|
+
rdoc (>= 4.0.0)
|
|
59
|
+
reline (>= 0.4.2)
|
|
60
|
+
json (2.18.0)
|
|
61
|
+
language_server-protocol (3.17.0.5)
|
|
62
|
+
lint_roller (1.1.0)
|
|
63
|
+
logger (1.7.0)
|
|
64
|
+
method_source (1.1.0)
|
|
65
|
+
minitest (6.0.1)
|
|
66
|
+
prism (~> 1.5)
|
|
67
|
+
ostruct (0.6.3)
|
|
68
|
+
parallel (1.27.0)
|
|
69
|
+
parser (3.3.10.0)
|
|
70
|
+
ast (~> 2.4.1)
|
|
71
|
+
racc
|
|
72
|
+
pp (0.6.3)
|
|
73
|
+
prettyprint
|
|
74
|
+
prettyprint (0.2.0)
|
|
75
|
+
prism (1.7.0)
|
|
76
|
+
pry (0.16.0)
|
|
77
|
+
coderay (~> 1.1)
|
|
78
|
+
method_source (~> 1.0)
|
|
79
|
+
reline (>= 0.6.0)
|
|
80
|
+
pry-doc (1.6.0)
|
|
81
|
+
pry (~> 0.11)
|
|
82
|
+
yard (~> 0.9.11)
|
|
83
|
+
psych (5.3.1)
|
|
84
|
+
date
|
|
85
|
+
stringio
|
|
86
|
+
racc (1.8.1)
|
|
87
|
+
rainbow (3.1.1)
|
|
88
|
+
rake (13.4.2)
|
|
89
|
+
rdoc (7.0.3)
|
|
90
|
+
erb
|
|
91
|
+
psych (>= 4.0.0)
|
|
92
|
+
tsort
|
|
93
|
+
redcarpet (3.6.1)
|
|
94
|
+
regexp_parser (2.11.3)
|
|
95
|
+
reline (0.6.3)
|
|
96
|
+
io-console (~> 0.5)
|
|
97
|
+
rspec (3.13.2)
|
|
98
|
+
rspec-core (~> 3.13.0)
|
|
99
|
+
rspec-expectations (~> 3.13.0)
|
|
100
|
+
rspec-mocks (~> 3.13.0)
|
|
101
|
+
rspec-core (3.13.6)
|
|
102
|
+
rspec-support (~> 3.13.0)
|
|
103
|
+
rspec-expectations (3.13.5)
|
|
104
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
105
|
+
rspec-support (~> 3.13.0)
|
|
106
|
+
rspec-mocks (3.13.7)
|
|
107
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
108
|
+
rspec-support (~> 3.13.0)
|
|
109
|
+
rspec-support (3.13.6)
|
|
110
|
+
rubocop (1.82.1)
|
|
111
|
+
json (~> 2.3)
|
|
112
|
+
language_server-protocol (~> 3.17.0.2)
|
|
113
|
+
lint_roller (~> 1.1.0)
|
|
114
|
+
parallel (~> 1.10)
|
|
115
|
+
parser (>= 3.3.0.2)
|
|
116
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
117
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
118
|
+
rubocop-ast (>= 1.48.0, < 2.0)
|
|
119
|
+
ruby-progressbar (~> 1.7)
|
|
120
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
121
|
+
rubocop-ast (1.48.0)
|
|
122
|
+
parser (>= 3.3.7.2)
|
|
123
|
+
prism (~> 1.4)
|
|
124
|
+
rubocop-performance (1.26.1)
|
|
125
|
+
lint_roller (~> 1.1)
|
|
126
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
127
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
128
|
+
rubocop-rake (0.7.1)
|
|
129
|
+
lint_roller (~> 1.1)
|
|
130
|
+
rubocop (>= 1.72.1)
|
|
131
|
+
rubocop-rspec (3.8.0)
|
|
132
|
+
lint_roller (~> 1.1)
|
|
133
|
+
rubocop (~> 1.81)
|
|
134
|
+
ruby-progressbar (1.13.0)
|
|
135
|
+
securerandom (0.4.1)
|
|
136
|
+
simplecov (0.22.0)
|
|
137
|
+
docile (~> 1.1)
|
|
138
|
+
simplecov-html (~> 0.11)
|
|
139
|
+
simplecov_json_formatter (~> 0.1)
|
|
140
|
+
simplecov-html (0.13.2)
|
|
141
|
+
simplecov_json_formatter (0.1.4)
|
|
142
|
+
stringio (3.2.0)
|
|
143
|
+
tsort (0.2.0)
|
|
144
|
+
tzinfo (2.0.6)
|
|
145
|
+
concurrent-ruby (~> 1.0)
|
|
146
|
+
unicode-display_width (3.2.0)
|
|
147
|
+
unicode-emoji (~> 4.1)
|
|
148
|
+
unicode-emoji (4.2.0)
|
|
149
|
+
uri (1.1.1)
|
|
150
|
+
yard (0.9.45)
|
|
151
|
+
|
|
152
|
+
PLATFORMS
|
|
153
|
+
ruby
|
|
154
|
+
x86_64-linux
|
|
155
|
+
|
|
156
|
+
DEPENDENCIES
|
|
157
|
+
bundler
|
|
158
|
+
debug (>= 1.0.0)
|
|
159
|
+
fat_core!
|
|
160
|
+
gem_docs (>= 0.2.0)
|
|
161
|
+
pry
|
|
162
|
+
pry-doc
|
|
163
|
+
rake
|
|
164
|
+
redcarpet
|
|
165
|
+
rspec
|
|
166
|
+
rubocop
|
|
167
|
+
rubocop-ddoherty!
|
|
168
|
+
simplecov
|
|
169
|
+
|
|
170
|
+
BUNDLED WITH
|
|
171
|
+
4.0.17
|
data/README.md
CHANGED
|
@@ -1,50 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
- [
|
|
4
|
-
- [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
- [Method `#
|
|
9
|
-
- [Method `
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- [Method `#
|
|
16
|
-
|
|
17
|
-
- [Method `#
|
|
18
|
-
- [Method `#
|
|
19
|
-
- [
|
|
20
|
-
|
|
21
|
-
- [Method `#
|
|
22
|
-
- [
|
|
23
|
-
|
|
24
|
-
- [Method `#
|
|
25
|
-
|
|
26
|
-
- [Methods `#
|
|
27
|
-
- [Method `#
|
|
28
|
-
|
|
29
|
-
- [Methods `#
|
|
30
|
-
|
|
31
|
-
- [Method `#
|
|
32
|
-
- [
|
|
33
|
-
|
|
34
|
-
- [
|
|
35
|
-
- [Method `#
|
|
36
|
-
- [Method `#
|
|
37
|
-
- [Method `#
|
|
38
|
-
- [Method `
|
|
39
|
-
|
|
40
|
-
- [Method `#
|
|
41
|
-
|
|
42
|
-
- [
|
|
1
|
+
<!-- Generated by gem_docs -->
|
|
2
|
+
|
|
3
|
+
- [Version](#org787cea4)
|
|
4
|
+
- [Introduction](#org70c35ee)
|
|
5
|
+
- [Installation](#org090e9a8)
|
|
6
|
+
- [Usage](#orgb94112e)
|
|
7
|
+
- [Array](#orgae8577a)
|
|
8
|
+
- [Method `#comma_join(sep: nil, last_sep: nil, two_sep: nil)`](#orgd8a835f)
|
|
9
|
+
- [Method `#last_i`](#org79540b4)
|
|
10
|
+
- [Method `#intersect_with_dups`](#orgb9df212)
|
|
11
|
+
- [Method `diff_with_dups`](#orgc551cb3)
|
|
12
|
+
- [BigDecimal](#org677499e)
|
|
13
|
+
- [Method `#inspect`](#org0d67a84)
|
|
14
|
+
- [Enumerable](#org3cbe0cd)
|
|
15
|
+
- [Method `#each_with_flags`](#org69aa600)
|
|
16
|
+
- [Hash](#org50ebe3a)
|
|
17
|
+
- [Method `#each_pair_with_flags`](#orgd73a8ff)
|
|
18
|
+
- [Method `#delete_with_value` and `#delete_with_value!`](#orgbfb1b2d)
|
|
19
|
+
- [Method `#keys_with_value`](#orgeb6b146)
|
|
20
|
+
- [Method `#remap_keys`](#orgd790229)
|
|
21
|
+
- [Method `#replace_keys`](#org1518994)
|
|
22
|
+
- [Alias `#merge` to `<<`](#orgccb5427)
|
|
23
|
+
- [Numeric](#org8796af2)
|
|
24
|
+
- [Method `#signum`](#org8788ba9)
|
|
25
|
+
- [Method `#commas(places = nil)`](#orga054f52)
|
|
26
|
+
- [Methods `#whole?` and `#int_if_whole`](#orgc67ff25)
|
|
27
|
+
- [Method `#secs_to_hms`](#orgd1d5330)
|
|
28
|
+
- [Range](#org23fcfd6)
|
|
29
|
+
- [Methods `#contiguous`, `#left_contiguous`, `#right_contiguous`](#org9c96e6a)
|
|
30
|
+
- [Method `#join(other)`](#org7ce66d2)
|
|
31
|
+
- [Method `#spanned_by?(others)`](#org84b3a46)
|
|
32
|
+
- [Methods `#gaps(others)`, `#overlaps(others)`](#org7873f20)
|
|
33
|
+
- [String](#org185182e)
|
|
34
|
+
- [Inspecting compiled matchers](#org5aface9)
|
|
35
|
+
- [Method `#fuzzy_match`](#org48e4298)
|
|
36
|
+
- [Method `#matches_with`](#org6d57e8b)
|
|
37
|
+
- [Method `#entitle`](#org52ff40e)
|
|
38
|
+
- [Method `#distance`](#org3c83e29)
|
|
39
|
+
- [Method `#commas(places)`](#org55c0282)
|
|
40
|
+
- [Method `#wrap(width, hang)`](#org7e7e1fe)
|
|
41
|
+
- [Method `#as_sym`](#orgedcd6ea)
|
|
42
|
+
- [Method `gut`](#org5bbf8f0)
|
|
43
|
+
- [Symbol](#orgb31753f)
|
|
44
|
+
- [Method `#as_str`](#orgfff0afa)
|
|
45
|
+
- [TeX Quoting](#org49836ae)
|
|
46
|
+
- [Contributing](#orga6d91af)
|
|
47
|
+
|
|
48
|
+
Version: 7.5.0
|
|
43
49
|
|
|
44
50
|
[](https://github.com/ddoherty03/fat_core/actions/workflows/ruby.yml)
|
|
45
51
|
|
|
46
52
|
|
|
47
|
-
<a id="
|
|
53
|
+
<a id="org787cea4"></a>
|
|
48
54
|
|
|
49
55
|
# Version
|
|
50
56
|
|
|
@@ -53,18 +59,18 @@
|
|
|
53
59
|
```
|
|
54
60
|
|
|
55
61
|
```
|
|
56
|
-
Current version is: 7.
|
|
62
|
+
Current version is: 7.5.0
|
|
57
63
|
```
|
|
58
64
|
|
|
59
65
|
|
|
60
|
-
<a id="
|
|
66
|
+
<a id="org70c35ee"></a>
|
|
61
67
|
|
|
62
68
|
# Introduction
|
|
63
69
|
|
|
64
70
|
`fat-core` is somewhat of a grab bag of core class extensions that I have found useful across several projects. It's higgeldy-piggeldy nature reflects the fact that none of them are important enough to deserve a gem of their own, but nonetheless need to be collected in one place to reduce redundancy across projects and provide a focused place to develop and test them.
|
|
65
71
|
|
|
66
72
|
|
|
67
|
-
<a id="
|
|
73
|
+
<a id="org090e9a8"></a>
|
|
68
74
|
|
|
69
75
|
# Installation
|
|
70
76
|
|
|
@@ -87,7 +93,7 @@ $ gem install fat_core
|
|
|
87
93
|
```
|
|
88
94
|
|
|
89
95
|
|
|
90
|
-
<a id="
|
|
96
|
+
<a id="orgb94112e"></a>
|
|
91
97
|
|
|
92
98
|
# Usage
|
|
93
99
|
|
|
@@ -118,12 +124,12 @@ false
|
|
|
118
124
|
Many of these have little that is of general interest, but there are a few goodies.
|
|
119
125
|
|
|
120
126
|
|
|
121
|
-
<a id="
|
|
127
|
+
<a id="orgae8577a"></a>
|
|
122
128
|
|
|
123
129
|
## Array
|
|
124
130
|
|
|
125
131
|
|
|
126
|
-
<a id="
|
|
132
|
+
<a id="orgd8a835f"></a>
|
|
127
133
|
|
|
128
134
|
### Method `#comma_join(sep: nil, last_sep: nil, two_sep: nil)`
|
|
129
135
|
|
|
@@ -166,7 +172,7 @@ hammers, nails, glue and bolts
|
|
|
166
172
|
```
|
|
167
173
|
|
|
168
174
|
|
|
169
|
-
<a id="
|
|
175
|
+
<a id="org79540b4"></a>
|
|
170
176
|
|
|
171
177
|
### Method `#last_i`
|
|
172
178
|
|
|
@@ -181,7 +187,7 @@ Return the index of the last element of the Array.
|
|
|
181
187
|
```
|
|
182
188
|
|
|
183
189
|
|
|
184
|
-
<a id="
|
|
190
|
+
<a id="orgb9df212"></a>
|
|
185
191
|
|
|
186
192
|
### Method `#intersect_with_dups`
|
|
187
193
|
|
|
@@ -198,7 +204,7 @@ a.intersect_with_dups(b)
|
|
|
198
204
|
```
|
|
199
205
|
|
|
200
206
|
|
|
201
|
-
<a id="
|
|
207
|
+
<a id="orgc551cb3"></a>
|
|
202
208
|
|
|
203
209
|
### Method `diff_with_dups`
|
|
204
210
|
|
|
@@ -215,9 +221,14 @@ a.diff_with_dups(b)
|
|
|
215
221
|
```
|
|
216
222
|
|
|
217
223
|
|
|
218
|
-
<a id="
|
|
224
|
+
<a id="org677499e"></a>
|
|
219
225
|
|
|
220
|
-
## BigDecimal
|
|
226
|
+
## BigDecimal
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
<a id="org0d67a84"></a>
|
|
230
|
+
|
|
231
|
+
### Method `#inspect`
|
|
221
232
|
|
|
222
233
|
`FatCore` provides nothing but a better `#inspect` method for the `BigDecimal` class since the default inspect method is not very readable.
|
|
223
234
|
|
|
@@ -232,12 +243,12 @@ BigDecimal('2.1718281828').inspect
|
|
|
232
243
|
Without `FatCore`, the result is "0.2718281828e1", forcing you to interpret the exponent to understand where the decimal place is.
|
|
233
244
|
|
|
234
245
|
|
|
235
|
-
<a id="
|
|
246
|
+
<a id="org3cbe0cd"></a>
|
|
236
247
|
|
|
237
248
|
## Enumerable
|
|
238
249
|
|
|
239
250
|
|
|
240
|
-
<a id="
|
|
251
|
+
<a id="org69aa600"></a>
|
|
241
252
|
|
|
242
253
|
### Method `#each_with_flags`
|
|
243
254
|
|
|
@@ -271,14 +282,14 @@ result
|
|
|
271
282
|
```
|
|
272
283
|
|
|
273
284
|
|
|
274
|
-
<a id="
|
|
285
|
+
<a id="org50ebe3a"></a>
|
|
275
286
|
|
|
276
287
|
## Hash
|
|
277
288
|
|
|
278
289
|
FatCore::Hash extends the Hash class with some useful methods.
|
|
279
290
|
|
|
280
291
|
|
|
281
|
-
<a id="
|
|
292
|
+
<a id="orgd73a8ff"></a>
|
|
282
293
|
|
|
283
294
|
### Method `#each_pair_with_flags`
|
|
284
295
|
|
|
@@ -316,7 +327,7 @@ result
|
|
|
316
327
|
```
|
|
317
328
|
|
|
318
329
|
|
|
319
|
-
<a id="
|
|
330
|
+
<a id="orgbfb1b2d"></a>
|
|
320
331
|
|
|
321
332
|
### Method `#delete_with_value` and `#delete_with_value!`
|
|
322
333
|
|
|
@@ -329,7 +340,7 @@ puts h
|
|
|
329
340
|
```
|
|
330
341
|
|
|
331
342
|
```
|
|
332
|
-
{:
|
|
343
|
+
{a: 1, c: 3, e: 1}
|
|
333
344
|
```
|
|
334
345
|
|
|
335
346
|
You can supply multiple values for deletion:
|
|
@@ -341,7 +352,7 @@ puts h
|
|
|
341
352
|
```
|
|
342
353
|
|
|
343
354
|
```
|
|
344
|
-
{:
|
|
355
|
+
{b: 2, d: 2}
|
|
345
356
|
```
|
|
346
357
|
|
|
347
358
|
The non-bang method returns a clone of the Hash with the given deletions made:
|
|
@@ -354,12 +365,12 @@ puts h2
|
|
|
354
365
|
```
|
|
355
366
|
|
|
356
367
|
```
|
|
357
|
-
{:
|
|
358
|
-
{:
|
|
368
|
+
{a: 1, b: 2, c: 3, d: 2, e: 1}
|
|
369
|
+
{b: 2, d: 2}
|
|
359
370
|
```
|
|
360
371
|
|
|
361
372
|
|
|
362
|
-
<a id="
|
|
373
|
+
<a id="orgeb6b146"></a>
|
|
363
374
|
|
|
364
375
|
### Method `#keys_with_value`
|
|
365
376
|
|
|
@@ -384,7 +395,7 @@ h.keys_with_value(2, 3).inspect
|
|
|
384
395
|
```
|
|
385
396
|
|
|
386
397
|
|
|
387
|
-
<a id="
|
|
398
|
+
<a id="orgd790229"></a>
|
|
388
399
|
|
|
389
400
|
### Method `#remap_keys`
|
|
390
401
|
|
|
@@ -398,7 +409,7 @@ h.remap_keys({:a => :A, :b => :B}).inspect
|
|
|
398
409
|
```
|
|
399
410
|
|
|
400
411
|
```
|
|
401
|
-
"{:
|
|
412
|
+
"{A: 1, B: 2, c: 3, d: 2, e: 1}"
|
|
402
413
|
```
|
|
403
414
|
|
|
404
415
|
These days, a more systematic job could be done with `#transform_keys`:
|
|
@@ -409,11 +420,11 @@ h.transform_keys { |k| k.to_s.upcase.to_sym }.inspect
|
|
|
409
420
|
```
|
|
410
421
|
|
|
411
422
|
```
|
|
412
|
-
"{:
|
|
423
|
+
"{A: 1, B: 2, C: 3, D: 2, E: 1}"
|
|
413
424
|
```
|
|
414
425
|
|
|
415
426
|
|
|
416
|
-
<a id="
|
|
427
|
+
<a id="org1518994"></a>
|
|
417
428
|
|
|
418
429
|
### Method `#replace_keys`
|
|
419
430
|
|
|
@@ -425,11 +436,11 @@ h.replace_keys([:z, :y, :x, :w, :v]).inspect
|
|
|
425
436
|
```
|
|
426
437
|
|
|
427
438
|
```
|
|
428
|
-
"{:
|
|
439
|
+
"{z: 1, y: 2, x: 3, w: 2, v: 1}"
|
|
429
440
|
```
|
|
430
441
|
|
|
431
442
|
|
|
432
|
-
<a id="
|
|
443
|
+
<a id="orgccb5427"></a>
|
|
433
444
|
|
|
434
445
|
### Alias `#merge` to `<<`
|
|
435
446
|
|
|
@@ -440,7 +451,7 @@ Finally, `FatCore` adds the "shovel" operator as an alias for `#merge` to provid
|
|
|
440
451
|
```
|
|
441
452
|
|
|
442
453
|
```
|
|
443
|
-
{:
|
|
454
|
+
{a: "A", b: "B", c: "CC", d: "DDD", e: "EEE"}
|
|
444
455
|
```
|
|
445
456
|
|
|
446
457
|
It groups values into pairs and applies the `#to_h` method to the right-hand argument if it is an `Enumerable`, so it also works if the right-hand argument is an `Array` or `Enumerable`:
|
|
@@ -464,18 +475,18 @@ h
|
|
|
464
475
|
```
|
|
465
476
|
|
|
466
477
|
```
|
|
467
|
-
{:
|
|
478
|
+
{a: "A", b: "B", c: "CC", d: "DDD", e: "EEE", "f" => "FFFF", "g" => "GGGG", h: "HHHHH", j: "JJJJJ"}
|
|
468
479
|
```
|
|
469
480
|
|
|
470
481
|
|
|
471
|
-
<a id="
|
|
482
|
+
<a id="org8796af2"></a>
|
|
472
483
|
|
|
473
484
|
## Numeric
|
|
474
485
|
|
|
475
486
|
FatCore::Numeric has methods for inserting grouping commas into a number (`#commas` and `#group`), for converting seconds to HH:MM:SS.dd format (`#secs_to_hms`), for testing for integrality (`#whole?` and `#int_if_whole`), and testing for sign (`#signum`).
|
|
476
487
|
|
|
477
488
|
|
|
478
|
-
<a id="
|
|
489
|
+
<a id="org8788ba9"></a>
|
|
479
490
|
|
|
480
491
|
### Method `#signum`
|
|
481
492
|
|
|
@@ -490,7 +501,7 @@ Return `-1` for negative numbers, `0` for zero, and `+1` for positive numbers. T
|
|
|
490
501
|
```
|
|
491
502
|
|
|
492
503
|
|
|
493
|
-
<a id="
|
|
504
|
+
<a id="orga054f52"></a>
|
|
494
505
|
|
|
495
506
|
### Method `#commas(places = nil)`
|
|
496
507
|
|
|
@@ -531,7 +542,7 @@ result
|
|
|
531
542
|
```
|
|
532
543
|
|
|
533
544
|
|
|
534
|
-
<a id="
|
|
545
|
+
<a id="orgc67ff25"></a>
|
|
535
546
|
|
|
536
547
|
### Methods `#whole?` and `#int_if_whole`
|
|
537
548
|
|
|
@@ -559,7 +570,7 @@ result
|
|
|
559
570
|
```
|
|
560
571
|
|
|
561
572
|
|
|
562
|
-
<a id="
|
|
573
|
+
<a id="orgd1d5330"></a>
|
|
563
574
|
|
|
564
575
|
### Method `#secs_to_hms`
|
|
565
576
|
|
|
@@ -587,14 +598,14 @@ result
|
|
|
587
598
|
```
|
|
588
599
|
|
|
589
600
|
|
|
590
|
-
<a id="
|
|
601
|
+
<a id="org23fcfd6"></a>
|
|
591
602
|
|
|
592
603
|
## Range
|
|
593
604
|
|
|
594
605
|
`FatCore` can also extend the Range class with several useful methods that emphasize coverage of one range by one or more others (`#spanned_by?` and `#gaps`), contiguity of Ranges to one another (`#contiguous?`, `#left_contiguous?`, and `#right_contiguous?`, `#join`), and the testing of overlaps between ranges (`#overlaps?`, `#overlaps_among?`). These are put to good use in the 'fat\_period' (<https://github.com/ddoherty03/fat_period>) gem, which combines fat\_core's extended Range class with its extended Date class to make a useful Period class for date ranges, and you may find fat\_core's extended Range class likewise useful.
|
|
595
606
|
|
|
596
607
|
|
|
597
|
-
<a id="
|
|
608
|
+
<a id="org9c96e6a"></a>
|
|
598
609
|
|
|
599
610
|
### Methods `#contiguous`, `#left_contiguous`, `#right_contiguous`
|
|
600
611
|
|
|
@@ -633,12 +644,12 @@ result
|
|
|
633
644
|
| 3.146..12.3 | 0.5..3.145 | false | false | false |
|
|
634
645
|
| a..q | r..z | true | true | false |
|
|
635
646
|
| a..q | s..z | false | false | false |
|
|
636
|
-
| 1963-11-22..1964-11-03 | 1964-11-04..2026-
|
|
637
|
-
| 1963-11-22..1964-11-03 | 1964-11-28..2026-
|
|
647
|
+
| 1963-11-22..1964-11-03 | 1964-11-04..2026-11-28 | true | true | false |
|
|
648
|
+
| 1963-11-22..1964-11-03 | 1964-11-28..2026-11-28 | false | false | false |
|
|
638
649
|
```
|
|
639
650
|
|
|
640
651
|
|
|
641
|
-
<a id="
|
|
652
|
+
<a id="org7ce66d2"></a>
|
|
642
653
|
|
|
643
654
|
### Method `#join(other)`
|
|
644
655
|
|
|
@@ -677,12 +688,12 @@ result
|
|
|
677
688
|
| 3.146..12.3 | 0.5..3.145 | false | |
|
|
678
689
|
| a..q | r..z | true | a..z |
|
|
679
690
|
| a..q | s..z | false | |
|
|
680
|
-
| 1963-11-22..1964-11-03 | 1964-11-04..2026-
|
|
681
|
-
| 1963-11-22..1964-11-03 | 1964-11-28..2026-
|
|
691
|
+
| 1963-11-22..1964-11-03 | 1964-11-04..2026-11-28 | true | 1963-11-22..2026-11-28 |
|
|
692
|
+
| 1963-11-22..1964-11-03 | 1964-11-28..2026-11-28 | false | |
|
|
682
693
|
```
|
|
683
694
|
|
|
684
695
|
|
|
685
|
-
<a id="
|
|
696
|
+
<a id="org84b3a46"></a>
|
|
686
697
|
|
|
687
698
|
### Method `#spanned_by?(others)`
|
|
688
699
|
|
|
@@ -722,7 +733,7 @@ result
|
|
|
722
733
|
```
|
|
723
734
|
|
|
724
735
|
|
|
725
|
-
<a id="
|
|
736
|
+
<a id="org7873f20"></a>
|
|
726
737
|
|
|
727
738
|
### Methods `#gaps(others)`, `#overlaps(others)`
|
|
728
739
|
|
|
@@ -764,14 +775,21 @@ result
|
|
|
764
775
|
```
|
|
765
776
|
|
|
766
777
|
|
|
767
|
-
<a id="
|
|
778
|
+
<a id="org185182e"></a>
|
|
768
779
|
|
|
769
780
|
## String
|
|
770
781
|
|
|
771
|
-
FatCore::String has methods for performing matching of one string with another (`#matches_with`, `#fuzzy_match`), for converting a string to title-case as might by used in the title of a book (`#entitle`), for converting a String into a useable Symbol (`#as_sym`) and vice-versa (`#as_str` also `Symbol#as_str`), for wrapping with an optional hanging indent (`#wrap`), cleaning up errant spaces (`#clean`), and computing the
|
|
782
|
+
FatCore::String has methods for performing matching of one string with another (`#matches_with`, `#fuzzy_match`), for converting a string to title-case as might by used in the title of a book (`#entitle`), for converting a String into a useable Symbol (`#as_sym`) and vice-versa (`#as_str` also `Symbol#as_str`), for wrapping with an optional hanging indent (`#wrap`), cleaning up errant spaces (`#clean`), and computing the Levenshtein distance between strings (`#distance`). And several others.
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
<a id="org5aface9"></a>
|
|
786
|
+
|
|
787
|
+
### Inspecting compiled matchers
|
|
788
|
+
|
|
789
|
+
`pattern.matcher_regexp` returns the exact Ruby Regexp used by `subject.matches_with(pattern)`. For example, `'st:lukes'.matcher_regexp` returns `/st.*\blukes/i`. Explicit slash-delimited regex flags are preserved. For ordinary fuzzy patterns, apply this regex to the same punctuation- and whitespace-normalized subject used by `fuzzy_match`, not to the raw name. Use `pattern.fuzzy_regexp` for the regex specifically used by `fuzzy_match`. These methods expose compilation for diagnostics without performing a match.
|
|
772
790
|
|
|
773
791
|
|
|
774
|
-
<a id="
|
|
792
|
+
<a id="org48e4298"></a>
|
|
775
793
|
|
|
776
794
|
### Method `#fuzzy_match`
|
|
777
795
|
|
|
@@ -818,7 +836,7 @@ result
|
|
|
818
836
|
```
|
|
819
837
|
|
|
820
838
|
|
|
821
|
-
<a id="
|
|
839
|
+
<a id="org6d57e8b"></a>
|
|
822
840
|
|
|
823
841
|
### Method `#matches_with`
|
|
824
842
|
|
|
@@ -850,7 +868,7 @@ result
|
|
|
850
868
|
```
|
|
851
869
|
|
|
852
870
|
|
|
853
|
-
<a id="
|
|
871
|
+
<a id="org52ff40e"></a>
|
|
854
872
|
|
|
855
873
|
### Method `#entitle`
|
|
856
874
|
|
|
@@ -879,11 +897,11 @@ result
|
|
|
879
897
|
```
|
|
880
898
|
|
|
881
899
|
|
|
882
|
-
<a id="
|
|
900
|
+
<a id="org3c83e29"></a>
|
|
883
901
|
|
|
884
902
|
### Method `#distance`
|
|
885
903
|
|
|
886
|
-
`FatCore` provides `distance` as a simple wrapper around the
|
|
904
|
+
`FatCore` provides `distance` as a simple wrapper around the Levenshtein distance function in Ruby's bundled `DidYouMean` library. Insertions, deletions, and substitutions each count as one edit; swapping adjacent letters counts as two. Distances above 10 return 11, preserving the existing ceiling. No native extension is needed.
|
|
887
905
|
|
|
888
906
|
```ruby
|
|
889
907
|
result = []
|
|
@@ -907,7 +925,7 @@ result
|
|
|
907
925
|
```
|
|
908
926
|
|
|
909
927
|
|
|
910
|
-
<a id="
|
|
928
|
+
<a id="org55c0282"></a>
|
|
911
929
|
|
|
912
930
|
### Method `#commas(places)`
|
|
913
931
|
|
|
@@ -938,7 +956,7 @@ result
|
|
|
938
956
|
```
|
|
939
957
|
|
|
940
958
|
|
|
941
|
-
<a id="
|
|
959
|
+
<a id="org7e7e1fe"></a>
|
|
942
960
|
|
|
943
961
|
### Method `#wrap(width, hang)`
|
|
944
962
|
|
|
@@ -1042,7 +1060,7 @@ Four score and seven years ago our
|
|
|
1042
1060
|
```
|
|
1043
1061
|
|
|
1044
1062
|
|
|
1045
|
-
<a id="
|
|
1063
|
+
<a id="orgedcd6ea"></a>
|
|
1046
1064
|
|
|
1047
1065
|
### Method `#as_sym`
|
|
1048
1066
|
|
|
@@ -1057,7 +1075,7 @@ Convert a `String` to a `Symbol` by converting all letters to lower-case, replac
|
|
|
1057
1075
|
```
|
|
1058
1076
|
|
|
1059
1077
|
|
|
1060
|
-
<a id="
|
|
1078
|
+
<a id="org5bbf8f0"></a>
|
|
1061
1079
|
|
|
1062
1080
|
### Method `gut`
|
|
1063
1081
|
|
|
@@ -1118,12 +1136,12 @@ ClassAComonStock
|
|
|
1118
1136
|
```
|
|
1119
1137
|
|
|
1120
1138
|
|
|
1121
|
-
<a id="
|
|
1139
|
+
<a id="orgb31753f"></a>
|
|
1122
1140
|
|
|
1123
1141
|
## Symbol
|
|
1124
1142
|
|
|
1125
1143
|
|
|
1126
|
-
<a id="
|
|
1144
|
+
<a id="orgfff0afa"></a>
|
|
1127
1145
|
|
|
1128
1146
|
### Method `#as_str`
|
|
1129
1147
|
|
|
@@ -1138,7 +1156,7 @@ hello-to-the-world
|
|
|
1138
1156
|
```
|
|
1139
1157
|
|
|
1140
1158
|
|
|
1141
|
-
<a id="
|
|
1159
|
+
<a id="org49836ae"></a>
|
|
1142
1160
|
|
|
1143
1161
|
## TeX Quoting
|
|
1144
1162
|
|
|
@@ -1181,14 +1199,14 @@ result
|
|
|
1181
1199
|
| Complex | 5.0+3.0i | "$5+3i$" |
|
|
1182
1200
|
| Rational | 5/3 | "$\\frac{5}{3}$" |
|
|
1183
1201
|
| Rational | 8/17 | "$\\frac{8}{17}$" |
|
|
1184
|
-
| Range | 2020-09-22..2026-
|
|
1202
|
+
| Range | 2020-09-22..2026-11-28 | "(2020-09-22..2026-11-28)" |
|
|
1185
1203
|
| Range | 2.718281828459045..3.141592653589793 | "($e$..$\\pi$)" |
|
|
1186
1204
|
| Symbol | four_score_and_7_years | "four\\_score\\_and\\_7\\_years" |
|
|
1187
1205
|
| NilClass | | "" |
|
|
1188
1206
|
```
|
|
1189
1207
|
|
|
1190
1208
|
|
|
1191
|
-
<a id="
|
|
1209
|
+
<a id="orga6d91af"></a>
|
|
1192
1210
|
|
|
1193
1211
|
# Contributing
|
|
1194
1212
|
|
data/README.org
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
#+PROPERTY: header-args:sh :exports code :eval no
|
|
8
8
|
#+PROPERTY: header-args:bash :exports code :eval no
|
|
9
9
|
|
|
10
|
+
# gem_docs:version begin
|
|
11
|
+
Version: 7.5.0
|
|
12
|
+
# gem_docs:version end
|
|
13
|
+
|
|
14
|
+
|
|
10
15
|
#+BEGIN_EXPORT markdown
|
|
11
16
|
[](https://github.com/ddoherty03/fat_core/actions/workflows/ruby.yml)
|
|
12
17
|
#+END_EXPORT
|
|
@@ -18,7 +23,7 @@
|
|
|
18
23
|
|
|
19
24
|
#+RESULTS:
|
|
20
25
|
#+begin_example
|
|
21
|
-
Current version is: 7.
|
|
26
|
+
Current version is: 7.5.0
|
|
22
27
|
#+end_example
|
|
23
28
|
|
|
24
29
|
* Introduction
|
|
@@ -175,7 +180,8 @@ Array are included in the result /unless/ they also appear in any of the
|
|
|
175
180
|
| hammers | glue | bolts | hammers |
|
|
176
181
|
#+end_example
|
|
177
182
|
|
|
178
|
-
** BigDecimal
|
|
183
|
+
** BigDecimal
|
|
184
|
+
*** Method ~#inspect~
|
|
179
185
|
~FatCore~ provides nothing but a better ~#inspect~ method for the ~BigDecimal~
|
|
180
186
|
class since the default inspect method is not very readable.
|
|
181
187
|
|
|
@@ -279,7 +285,7 @@ equals the given value or values:
|
|
|
279
285
|
|
|
280
286
|
#+RESULTS:
|
|
281
287
|
#+begin_example
|
|
282
|
-
{:
|
|
288
|
+
{a: 1, c: 3, e: 1}
|
|
283
289
|
#+end_example
|
|
284
290
|
|
|
285
291
|
You can supply multiple values for deletion:
|
|
@@ -292,7 +298,7 @@ You can supply multiple values for deletion:
|
|
|
292
298
|
|
|
293
299
|
#+RESULTS:
|
|
294
300
|
#+begin_example
|
|
295
|
-
{:
|
|
301
|
+
{b: 2, d: 2}
|
|
296
302
|
#+end_example
|
|
297
303
|
|
|
298
304
|
The non-bang method returns a clone of the Hash with the given deletions made:
|
|
@@ -306,8 +312,8 @@ The non-bang method returns a clone of the Hash with the given deletions made:
|
|
|
306
312
|
|
|
307
313
|
#+RESULTS:
|
|
308
314
|
#+begin_example
|
|
309
|
-
{:
|
|
310
|
-
{:
|
|
315
|
+
{a: 1, b: 2, c: 3, d: 2, e: 1}
|
|
316
|
+
{b: 2, d: 2}
|
|
311
317
|
#+end_example
|
|
312
318
|
|
|
313
319
|
*** Method ~#keys_with_value~
|
|
@@ -349,7 +355,7 @@ original ~Hash~ is not effected.
|
|
|
349
355
|
|
|
350
356
|
#+RESULTS:
|
|
351
357
|
#+begin_example
|
|
352
|
-
"{:
|
|
358
|
+
"{A: 1, B: 2, c: 3, d: 2, e: 1}"
|
|
353
359
|
#+end_example
|
|
354
360
|
|
|
355
361
|
These days, a more systematic job could be done with ~#transform_keys~:
|
|
@@ -360,7 +366,7 @@ These days, a more systematic job could be done with ~#transform_keys~:
|
|
|
360
366
|
|
|
361
367
|
#+RESULTS:
|
|
362
368
|
#+begin_example
|
|
363
|
-
"{:
|
|
369
|
+
"{A: 1, B: 2, C: 3, D: 2, E: 1}"
|
|
364
370
|
#+end_example
|
|
365
371
|
|
|
366
372
|
*** Method ~#replace_keys~
|
|
@@ -373,7 +379,7 @@ A wholesale replacement of the existing keys can be done with this method:
|
|
|
373
379
|
|
|
374
380
|
#+RESULTS:
|
|
375
381
|
#+begin_example
|
|
376
|
-
"{:
|
|
382
|
+
"{z: 1, y: 2, x: 3, w: 2, v: 1}"
|
|
377
383
|
#+end_example
|
|
378
384
|
|
|
379
385
|
*** Alias ~#merge~ to ~<<~
|
|
@@ -387,7 +393,7 @@ provide a pretty way to represent the merger of the right ~Hash~ into the left
|
|
|
387
393
|
|
|
388
394
|
#+RESULTS:
|
|
389
395
|
#+begin_example
|
|
390
|
-
{:
|
|
396
|
+
{a: "A", b: "B", c: "CC", d: "DDD", e: "EEE"}
|
|
391
397
|
#+end_example
|
|
392
398
|
|
|
393
399
|
It groups values into pairs and applies the ~#to_h~ method to the right-hand
|
|
@@ -414,7 +420,7 @@ is an ~Array~ or ~Enumerable~:
|
|
|
414
420
|
|
|
415
421
|
#+RESULTS:
|
|
416
422
|
#+begin_example
|
|
417
|
-
{:
|
|
423
|
+
{a: "A", b: "B", c: "CC", d: "DDD", e: "EEE", "f" => "FFFF", "g" => "GGGG", h: "HHHHH", j: "JJJJJ"}
|
|
418
424
|
#+end_example
|
|
419
425
|
|
|
420
426
|
** Numeric
|
|
@@ -582,8 +588,8 @@ the max value of the left ~Range~ must equal the min value of the right
|
|
|
582
588
|
| 3.146..12.3 | 0.5..3.145 | false | false | false |
|
|
583
589
|
| a..q | r..z | true | true | false |
|
|
584
590
|
| a..q | s..z | false | false | false |
|
|
585
|
-
| 1963-11-22..1964-11-03 | 1964-11-04..2026-
|
|
586
|
-
| 1963-11-22..1964-11-03 | 1964-11-28..2026-
|
|
591
|
+
| 1963-11-22..1964-11-03 | 1964-11-04..2026-11-28 | true | true | false |
|
|
592
|
+
| 1963-11-22..1964-11-03 | 1964-11-28..2026-11-28 | false | false | false |
|
|
587
593
|
#+end_example
|
|
588
594
|
|
|
589
595
|
*** Method ~#join(other)~
|
|
@@ -624,8 +630,8 @@ two ~Range~s into one ~Range~.
|
|
|
624
630
|
| 3.146..12.3 | 0.5..3.145 | false | |
|
|
625
631
|
| a..q | r..z | true | a..z |
|
|
626
632
|
| a..q | s..z | false | |
|
|
627
|
-
| 1963-11-22..1964-11-03 | 1964-11-04..2026-
|
|
628
|
-
| 1963-11-22..1964-11-03 | 1964-11-28..2026-
|
|
633
|
+
| 1963-11-22..1964-11-03 | 1964-11-04..2026-11-28 | true | 1963-11-22..2026-11-28 |
|
|
634
|
+
| 1963-11-22..1964-11-03 | 1964-11-28..2026-11-28 | false | |
|
|
629
635
|
#+end_example
|
|
630
636
|
|
|
631
637
|
*** Method ~#spanned_by?(others)~
|
|
@@ -718,9 +724,18 @@ FatCore::String has methods for performing matching of one string with another
|
|
|
718
724
|
might by used in the title of a book (~#entitle~), for converting a String
|
|
719
725
|
into a useable Symbol (~#as_sym~) and vice-versa (~#as_str~ also
|
|
720
726
|
~Symbol#as_str~), for wrapping with an optional hanging indent (~#wrap~),
|
|
721
|
-
cleaning up errant spaces (~#clean~), and computing the
|
|
727
|
+
cleaning up errant spaces (~#clean~), and computing the Levenshtein
|
|
722
728
|
distance between strings (~#distance~). And several others.
|
|
723
729
|
|
|
730
|
+
*** Inspecting compiled matchers
|
|
731
|
+
~pattern.matcher_regexp~ returns the exact Ruby Regexp used by
|
|
732
|
+
~subject.matches_with(pattern)~. For example, ~'st:lukes'.matcher_regexp~
|
|
733
|
+
returns ~/st.*\blukes/i~. Explicit slash-delimited regex flags are preserved.
|
|
734
|
+
For ordinary fuzzy patterns, apply this regex to the same punctuation- and
|
|
735
|
+
whitespace-normalized subject used by ~fuzzy_match~, not to the raw name.
|
|
736
|
+
Use ~pattern.fuzzy_regexp~ for the regex specifically used by ~fuzzy_match~.
|
|
737
|
+
These methods expose compilation for diagnostics without performing a match.
|
|
738
|
+
|
|
724
739
|
*** Method ~#fuzzy_match~
|
|
725
740
|
The ~#fuzzy_match~ method determines whether the subject string matches the
|
|
726
741
|
given "matcher" string, which provides a simple syntax that allows a limited
|
|
@@ -851,8 +866,10 @@ something like "In the Heat of the Night".
|
|
|
851
866
|
|
|
852
867
|
*** Method ~#distance~
|
|
853
868
|
~FatCore~ provides ~distance~ as a simple wrapper around the
|
|
854
|
-
|
|
855
|
-
|
|
869
|
+
Levenshtein distance function in Ruby's bundled ~DidYouMean~ library.
|
|
870
|
+
Insertions, deletions, and substitutions each count as one edit; swapping
|
|
871
|
+
adjacent letters counts as two. Distances above 10 return 11, preserving
|
|
872
|
+
the existing ceiling. No native extension is needed.
|
|
856
873
|
|
|
857
874
|
#+begin_src ruby
|
|
858
875
|
result = []
|
|
@@ -1152,7 +1169,7 @@ deploys TeX notation when special notation is available, for example, a
|
|
|
1152
1169
|
| Complex | 5.0+3.0i | "$5+3i$" |
|
|
1153
1170
|
| Rational | 5/3 | "$\\frac{5}{3}$" |
|
|
1154
1171
|
| Rational | 8/17 | "$\\frac{8}{17}$" |
|
|
1155
|
-
| Range | 2020-09-22..2026-
|
|
1172
|
+
| Range | 2020-09-22..2026-11-28 | "(2020-09-22..2026-11-28)" |
|
|
1156
1173
|
| Range | 2.718281828459045..3.141592653589793 | "($e$..$\\pi$)" |
|
|
1157
1174
|
| Symbol | four_score_and_7_years | "four\\_score\\_and\\_7\\_years" |
|
|
1158
1175
|
| NilClass | | "" |
|
data/fat_core.gemspec
CHANGED
data/lib/fat_core/string.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'bigdecimal'
|
|
4
4
|
require 'fat_core/patches'
|
|
5
|
-
require '
|
|
5
|
+
require 'did_you_mean/levenshtein'
|
|
6
6
|
require 'active_support/core_ext/regexp'
|
|
7
7
|
require_relative 'numeric'
|
|
8
8
|
|
|
@@ -215,14 +215,14 @@ module FatCore
|
|
|
215
215
|
# @group Matching
|
|
216
216
|
# :section: Matching
|
|
217
217
|
|
|
218
|
-
# Return the
|
|
219
|
-
#
|
|
220
|
-
#
|
|
218
|
+
# Return the Levenshtein distance between self and another string.
|
|
219
|
+
# Distances above 10 return 11, preserving the existing ceiling.
|
|
220
|
+
# Swapping adjacent characters counts as two edits.
|
|
221
221
|
#
|
|
222
222
|
# @param other [#to_s] string to compute self's distance from
|
|
223
223
|
# @return [Integer] the distance between self and other
|
|
224
224
|
def distance(other)
|
|
225
|
-
|
|
225
|
+
[DidYouMean::Levenshtein.distance(self, other.to_s), 11].min
|
|
226
226
|
end
|
|
227
227
|
|
|
228
228
|
# Return the matched portion of self, with fuzzy-match punctuation normalized,
|
|
@@ -267,19 +267,30 @@ module FatCore
|
|
|
267
267
|
# @return [String] the portion of the subject that matched
|
|
268
268
|
# @return [nil] if the subject did not match
|
|
269
269
|
def fuzzy_match(matcher)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
270
|
+
subject = matcher.match?(%r{\A/.*/\z}) ? self : fuzzy_match_clean(self)
|
|
271
|
+
match = matcher.fuzzy_regexp.match(subject)
|
|
272
|
+
match[0] if match
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Compile self as a fuzzy matcher. Ordinary patterns match normalized
|
|
276
|
+
# subjects (see #fuzzy_match); slash-wrapped regexes match original text.
|
|
277
|
+
# @return [Regexp]
|
|
278
|
+
def fuzzy_regexp
|
|
279
|
+
if match?(%r{\A/.*/\z})
|
|
280
|
+
Regexp.new(self[1...-1], Regexp::IGNORECASE)
|
|
273
281
|
else
|
|
274
|
-
|
|
275
|
-
matcher = fuzzy_match_clean(matcher)
|
|
276
|
-
regexp = Regexp.new(fuzzy_match_regexp(matcher), Regexp::IGNORECASE)
|
|
282
|
+
Regexp.new(fuzzy_match_regexp(fuzzy_match_clean(self)), Regexp::IGNORECASE)
|
|
277
283
|
end
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Return the exact regex used when self is passed to #matches_with.
|
|
287
|
+
# Explicit regex modifiers are preserved; fuzzy regexes operate on
|
|
288
|
+
# punctuation/whitespace-normalized subjects, not the original text.
|
|
289
|
+
# @example
|
|
290
|
+
# 'st:lukes'.matcher_regexp #=> /st.*\\blukes/i
|
|
291
|
+
# @return [Regexp]
|
|
292
|
+
def matcher_regexp
|
|
293
|
+
match?(%r{^\s*/}) ? as_regexp : fuzzy_regexp
|
|
283
294
|
end
|
|
284
295
|
|
|
285
296
|
# Test whether self matches the `matcher` treating `matcher` as a
|
|
@@ -295,13 +306,9 @@ module FatCore
|
|
|
295
306
|
def matches_with(matcher)
|
|
296
307
|
return if matcher.nil?
|
|
297
308
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
md[0] if md
|
|
302
|
-
else
|
|
303
|
-
fuzzy_match(matcher)
|
|
304
|
-
end
|
|
309
|
+
subject = matcher.match?(%r{^\s*/}) ? self : fuzzy_match_clean(self)
|
|
310
|
+
match = matcher.matcher_regexp.match(subject)
|
|
311
|
+
match[0] if match
|
|
305
312
|
end
|
|
306
313
|
|
|
307
314
|
# Convert a string of the form '/.../Iixm' to a regular
|
|
@@ -377,8 +384,6 @@ module FatCore
|
|
|
377
384
|
to_f.commas(places)
|
|
378
385
|
end
|
|
379
386
|
|
|
380
|
-
private
|
|
381
|
-
|
|
382
387
|
def fuzzy_match_regexp(matcher)
|
|
383
388
|
start_anchor = matcher.start_with?(':')
|
|
384
389
|
end_anchor = matcher.end_with?(':')
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/string_spec.rb
CHANGED
|
@@ -246,7 +246,7 @@ the people, for the people, shall not perish from the earth."
|
|
|
246
246
|
end
|
|
247
247
|
|
|
248
248
|
it 'computes its Levenshtein distance from another string' do
|
|
249
|
-
expect('Something'.distance('Smoething')).to eq
|
|
249
|
+
expect('Something'.distance('Smoething')).to eq 2
|
|
250
250
|
expect('Something'.distance('meSothing')).to eq 4
|
|
251
251
|
expect('SomethingElse'.distance('Encyclopedia')).to eq 11
|
|
252
252
|
expect('SomethingElseUnrelated'.distance('EncyclopediaBritanica'))
|
|
@@ -254,6 +254,20 @@ the people, for the people, shall not perish from the earth."
|
|
|
254
254
|
expect('SomethingElseUnrelated'.distance('EncyclopediaBritanica')).to eq 11
|
|
255
255
|
end
|
|
256
256
|
|
|
257
|
+
it 'handles identical, empty, Unicode, and non-string inputs' do
|
|
258
|
+
expect('same'.distance('same')).to eq 0
|
|
259
|
+
expect(''.distance('abc')).to eq 3
|
|
260
|
+
expect('abc'.distance('')).to eq 3
|
|
261
|
+
expect('café'.distance('cafe')).to eq 1
|
|
262
|
+
expect('123'.distance(123)).to eq 0
|
|
263
|
+
expect(''.distance(nil)).to eq 0
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it 'caps distances above ten at eleven' do
|
|
267
|
+
expect(('a' * 10).distance('')).to eq 10
|
|
268
|
+
expect(('a' * 12).distance('')).to eq 11
|
|
269
|
+
end
|
|
270
|
+
|
|
257
271
|
describe 'Quoting' do
|
|
258
272
|
it 'quotes special TeX characters' do
|
|
259
273
|
expect('$10,000'.tex_quote).to eq('\\$10,000')
|
|
@@ -447,5 +461,23 @@ the people, for the people, shall not perish from the earth."
|
|
|
447
461
|
expect("St. Luke's Hospital".matches_with('/LUKE/I')).to be_nil
|
|
448
462
|
end
|
|
449
463
|
end
|
|
464
|
+
|
|
465
|
+
describe 'compiled string matchers' do
|
|
466
|
+
it 'exposes the fuzzy word-boundary pattern' do
|
|
467
|
+
expect('st:lukes'.matcher_regexp).to eq(/st.*\blukes/i)
|
|
468
|
+
expect("St. Luke's Hospital".matches_with('st:lukes')).to eq('St Lukes')
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
it 'preserves anchoring and normalized punctuation' do
|
|
472
|
+
expect(':Amazon.com:'.matcher_regexp).to eq(/\AAmazon.*com\z/i)
|
|
473
|
+
expect('Amazon.com'.matches_with(':Amazon.com:')).to eq('Amazon com')
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
it 'preserves explicit regex flags and matches original punctuation' do
|
|
477
|
+
expect('/Luke/I'.matcher_regexp).to eq(/Luke/)
|
|
478
|
+
expect('luke'.matches_with('/Luke/I')).to be_nil
|
|
479
|
+
expect("St. Luke's".matches_with('/St\\./')).to eq('St.')
|
|
480
|
+
end
|
|
481
|
+
end
|
|
450
482
|
end
|
|
451
483
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fat_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel E. Doherty
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
10
|
+
date: 2026-11-28 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -24,20 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: damerau-levenshtein
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
26
|
- !ruby/object:Gem::Dependency
|
|
42
27
|
name: ostruct
|
|
43
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -89,6 +74,7 @@ files:
|
|
|
89
74
|
- CHANGELOG.md
|
|
90
75
|
- CHANGELOG.org
|
|
91
76
|
- Gemfile
|
|
77
|
+
- Gemfile.lock
|
|
92
78
|
- LICENSE.txt
|
|
93
79
|
- README.md
|
|
94
80
|
- README.org
|
|
@@ -125,7 +111,6 @@ licenses:
|
|
|
125
111
|
- MIT
|
|
126
112
|
metadata:
|
|
127
113
|
yard.run: yri
|
|
128
|
-
post_install_message:
|
|
129
114
|
rdoc_options: []
|
|
130
115
|
require_paths:
|
|
131
116
|
- lib
|
|
@@ -140,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
140
125
|
- !ruby/object:Gem::Version
|
|
141
126
|
version: '0'
|
|
142
127
|
requirements: []
|
|
143
|
-
rubygems_version: 3.
|
|
144
|
-
signing_key:
|
|
128
|
+
rubygems_version: 3.6.2
|
|
145
129
|
specification_version: 4
|
|
146
130
|
summary: some useful core extensions
|
|
147
131
|
test_files: []
|