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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e41b6857fb2c0b81125ed588ea89a53fa65d794e462336d96186692de9f369b3
4
- data.tar.gz: 3ab1379a55487b58400c971dd81eb81d08aafe2500e4743e9402b646a6daddab
3
+ metadata.gz: 85d8ffad1ed87418cf2d6f2d05e2c08017b76a096d7c7fda5640cdb65f8aebcc
4
+ data.tar.gz: 44349fdd2663ada616693253dd9e382779cf4dcdeb8381ce1fe25bd021b02773
5
5
  SHA512:
6
- metadata.gz: 9da3d3dd996a3ffe907e618ee9f4ee550c3e720b8a27e8790d4f027c5e11b187417832e41bfe3d6d3c513c2315482302ed784dd61c87c98a2647483f838ea953
7
- data.tar.gz: e5862ca6b225780f8152611064e2c4af9550a7351f2fc44a4aae20c991d6802fc4261c605afbb5d8b99f6c3790934330571219a60ef4c7f93bf613935d83cc71
6
+ metadata.gz: db95df80a950888e53d2709c69529d30519604547232be544aec12da212459cd4a505dbc77221e4bd55760ce30ecc5665cac2301e317b7541b0714269c1ae092
7
+ data.tar.gz: da9bc4df559ff88f20e34b057a1bd9888193fdc5b316e01414139368f8f3b18816ff0296e335baf0655ece83c6f64a93841f540c1f2ffea2edecfa4ece6e4092
@@ -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
@@ -3,7 +3,7 @@
3
3
  module FatCore
4
4
  MAJOR = 7
5
5
  MINOR = 1
6
- PATCH = 1
6
+ PATCH = 3
7
7
 
8
8
  # FatCore version number
9
9
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -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 'performs examples in documentation with regexes' do
376
- expect("St. Luke's".matches_with('/st\s*lukes/')).to eq('St Lukes')
377
- expect("St. Luke's Hospital".matches_with('/st lukes/')).to eq('St Lukes')
378
- expect("St. Luke's Hospital".matches_with('/luk.*\bhosp/')).to eq('Lukes Hosp')
379
- expect("St. Luke's Hospital".matches_with('/st(.*)spital\z/')).to eq('St Lukes Hospital')
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('/lukes hospital/')).to eq('Lukes Hospital')
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.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-27 00:00:00.000000000 Z
11
+ date: 2025-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport