fat_core 7.1.1 → 7.1.3
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/lib/fat_core/string.rb +22 -23
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/string_spec.rb +13 -6
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85d8ffad1ed87418cf2d6f2d05e2c08017b76a096d7c7fda5640cdb65f8aebcc
|
|
4
|
+
data.tar.gz: 44349fdd2663ada616693253dd9e382779cf4dcdeb8381ce1fe25bd021b02773
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db95df80a950888e53d2709c69529d30519604547232be544aec12da212459cd4a505dbc77221e4bd55760ce30ecc5665cac2301e317b7541b0714269c1ae092
|
|
7
|
+
data.tar.gz: da9bc4df559ff88f20e34b057a1bd9888193fdc5b316e01414139368f8f3b18816ff0296e335baf0655ece83c6f64a93841f540c1f2ffea2edecfa4ece6e4092
|
data/lib/fat_core/string.rb
CHANGED
|
@@ -215,29 +215,6 @@ module FatCore
|
|
|
215
215
|
DamerauLevenshtein.distance(self, other.to_s, 1, 10)
|
|
216
216
|
end
|
|
217
217
|
|
|
218
|
-
# Test whether self matches the `matcher` treating `matcher` as a
|
|
219
|
-
# case-insensitive regular expression if it is of the form '/.../' or as a
|
|
220
|
-
# string to #fuzzy_match against otherwise.
|
|
221
|
-
#
|
|
222
|
-
# @param matcher [String] regexp if looks like /.../; #fuzzy_match pattern otherwise
|
|
223
|
-
# @return [nil] if no match
|
|
224
|
-
# @return [String] the matched portion of self, with punctuation stripped in
|
|
225
|
-
# case of #fuzzy_match
|
|
226
|
-
# @see #fuzzy_match #fuzzy_match for the specifics of string matching
|
|
227
|
-
# @see #as_regexp #as_regexp for conversion of `matcher` to regular expression
|
|
228
|
-
def matches_with(matcher)
|
|
229
|
-
target = clean.gsub(/[\*.,']/, '')
|
|
230
|
-
if matcher.nil?
|
|
231
|
-
nil
|
|
232
|
-
elsif matcher.match?(%r{^\s*/})
|
|
233
|
-
re = matcher.as_regexp
|
|
234
|
-
md = target.match(re)
|
|
235
|
-
md[0] if md
|
|
236
|
-
else
|
|
237
|
-
to_s.fuzzy_match(matcher)
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
218
|
# Return the matched portion of self, minus punctuation characters, if self
|
|
242
219
|
# matches the string `matcher` using the following notion of matching:
|
|
243
220
|
#
|
|
@@ -301,6 +278,28 @@ module FatCore
|
|
|
301
278
|
matched_text
|
|
302
279
|
end
|
|
303
280
|
|
|
281
|
+
# Test whether self matches the `matcher` treating `matcher` as a
|
|
282
|
+
# case-insensitive regular expression if it is of the form '/.../' or as a
|
|
283
|
+
# string to #fuzzy_match against otherwise.
|
|
284
|
+
#
|
|
285
|
+
# @param matcher [String] regexp if looks like /.../; #fuzzy_match pattern otherwise
|
|
286
|
+
# @return [nil] if no match
|
|
287
|
+
# @return [String] the matched portion of self, with punctuation stripped in
|
|
288
|
+
# case of #fuzzy_match
|
|
289
|
+
# @see #fuzzy_match #fuzzy_match for the specifics of string matching
|
|
290
|
+
# @see #as_regexp #as_regexp for conversion of `matcher` to regular expression
|
|
291
|
+
def matches_with(matcher)
|
|
292
|
+
return if matcher.nil?
|
|
293
|
+
|
|
294
|
+
if matcher.match?(%r{^\s*/})
|
|
295
|
+
re = matcher.as_regexp
|
|
296
|
+
md = match(re)
|
|
297
|
+
md[0] if md
|
|
298
|
+
else
|
|
299
|
+
fuzzy_match(matcher)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
304
303
|
# Convert a string of the form '/.../Iixm' to a regular
|
|
305
304
|
# expression. However, make the regular expression case-insensitive by
|
|
306
305
|
# default and extend the modifier syntax to allow '/I' to indicate
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/string_spec.rb
CHANGED
|
@@ -372,15 +372,22 @@ the people, for the people, shall not perish from the earth."
|
|
|
372
372
|
expect("St. Luke's Hospital".matches_with('lukes:hospital')).to eq('Lukes Hospital')
|
|
373
373
|
end
|
|
374
374
|
|
|
375
|
-
it '
|
|
376
|
-
expect("St. Luke's".matches_with('
|
|
377
|
-
expect("St. Luke's Hospital".matches_with('
|
|
378
|
-
expect("St. Luke's
|
|
379
|
-
expect("St. Luke's Hospital".matches_with('/st
|
|
375
|
+
it 'does not pre-condition the subject when regexes' do
|
|
376
|
+
expect("St. Luke's Hospital".matches_with('st:lukes')).to eq('St Lukes')
|
|
377
|
+
expect("St. Luke's Hospital".matches_with('lukes')).to eq('Lukes')
|
|
378
|
+
expect("St. Luke's".matches_with('/st.*luke\'s/')).to eq('St. Luke\'s')
|
|
379
|
+
expect("St. Luke's Hospital".matches_with('/st\\. luke/')).to eq('St. Luke')
|
|
380
|
+
expect("St. Luke's Hospital".matches_with('/luk.*\bhosp/')).to eq('Luke\'s Hosp')
|
|
381
|
+
expect("St. Luke's Hospital".matches_with('/st(.*)spital\z/')).to eq('St. Luke\'s Hospital')
|
|
380
382
|
expect("St. Luke's Hospital".matches_with('/st spital/')).to be_nil
|
|
381
383
|
expect("St. Luke's Hospital".matches_with('/st.*laks/')).to be_nil
|
|
382
384
|
expect("St. Luke's Hospital".matches_with('/\Alukes/')).to be_nil
|
|
383
|
-
expect("St. Luke's Hospital".matches_with('/
|
|
385
|
+
expect("St. Luke's Hospital".matches_with('/luke.*hospital/')).to eq('Luke\'s Hospital')
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
it 'makes the regex case insensitive unless option I given' do
|
|
389
|
+
expect("St. Luke's Hospital".matches_with('/LUKE/')).to eq('Luke')
|
|
390
|
+
expect("St. Luke's Hospital".matches_with('/LUKE/I')).to be_nil
|
|
384
391
|
end
|
|
385
392
|
end
|
|
386
393
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fat_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.1.
|
|
4
|
+
version: 7.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel E. Doherty
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|