fat_core 4.10.0 → 4.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3860db07c85484c1d82e2fafa18d730e7dedb991f33868b21c2c11d3e56c7fde
4
- data.tar.gz: 524ca9b2ecdd017b5f14d8ff70e787d550bdf0a3eb4769be6442c3df914f965c
3
+ metadata.gz: 8607195b8f5ef6d04df1f438fbd59d3a22ca3a730d0d5bb9430ff37166d07174
4
+ data.tar.gz: e86aedc2aafebf6fc02efdf6f3f35f39ad93059b08a8bc4e635190e5964f2942
5
5
  SHA512:
6
- metadata.gz: fda77f07f98048d111fdf752b115595f1b3b79e8f2c6b1d73482edfcb9e89ad45f6d46331fca04b3cabab3f1ab2f4da91675de5b8c4965943aa12d4902501839
7
- data.tar.gz: 37a9824e50cdc58880d081007c70b9e5b4d6c338f381139ad178e936d68da24e19a6b188298072da9df7444b88eacfa9ed362bcb2767092abdb6f532e93e7089
6
+ metadata.gz: 94983a4893c2c4882b360236f488c3a741ea8927488a69785ae4a7cc8f93612e11aa1f6899b359fcc2bb25742d6f062d3c76f5cbd75dfc64c24edba44be45755
7
+ data.tar.gz: 9700b48e6c73ec9ec49ed7da22679b4ea90676be71011b4c4c912cb4b53c2d613bb1712b8c59f440990570a33ffe12ab51ec0986ace906638408b3bab85f59d9
@@ -245,28 +245,44 @@ module FatCore
245
245
  #
246
246
  # 1. Remove all periods, commas, apostrophes, and asterisks (the punctuation
247
247
  # characters) from both self and `matcher`,
248
- # 2. Treat ':' in the matcher as the equivalent of '.*' in a regular
249
- # expression, that is, match anything in self,
250
- # 3. Require each component to match the beginning of a word boundary
251
- # 4. Ignore case in the match
248
+ # 2. Treat internal ':' in the matcher as the equivalent of '.*' in a
249
+ # regular expression, that is, match anything in self,
250
+ # 3. Treat leading ':' in the matcher as anchoring the match to the
251
+ # beginning of the target string,
252
+ # 4. Treat ending ':' in the matcher as anchoring the match to the
253
+ # end of the target string,
254
+ # 5. Require each component to match the beginning of a word boundary
255
+ # 6. Ignore case in the match
252
256
  #
253
257
  # @example
254
258
  # "St. Luke's Hospital".fuzzy_match('st lukes') #=> 'St Lukes'
255
259
  # "St. Luke's Hospital".fuzzy_match('luk:hosp') #=> 'Lukes Hosp'
256
260
  # "St. Luke's Hospital".fuzzy_match('st:spital') #=> 'St Lukes Hospital'
257
261
  # "St. Luke's Hospital".fuzzy_match('st:laks') #=> nil
262
+ # "St. Luke's Hospital".fuzzy_match(':lukes') #=> nil
263
+ # "St. Luke's Hospital".fuzzy_match('lukes:hospital:') #=> 'Lukes Hospital'
258
264
  #
259
265
  # @param matcher [String] pattern to test against where ':' is wildcard
260
266
  # @return [String] the unpunctuated part of self that matched
261
267
  # @return [nil] if self did not match matcher
262
268
  def fuzzy_match(matcher)
263
269
  # Remove periods, asterisks, commas, and apostrophes
264
- matcher = matcher.gsub(/[\*.,']/, '')
270
+ matcher = matcher.strip.gsub(/[\*.,']/, '')
271
+ if matcher.start_with?(':')
272
+ begin_anchor = true
273
+ matcher.sub!(/\A:/, '')
274
+ end
275
+ if matcher.end_with?(':')
276
+ end_anchor = true
277
+ matcher.sub!(/:\z/, '')
278
+ end
265
279
  target = gsub(/[\*.,']/, '')
266
280
  matchers = matcher.split(/[: ]+/)
267
281
  regexp_string = matchers.map { |m| ".*?\\b#{Regexp.escape(m)}.*?" }.join('[: ]')
268
282
  regexp_string.sub!(/^\.\*\?/, '')
269
283
  regexp_string.sub!(/\.\*\?$/, '')
284
+ regexp_string.sub!(/\A/, '\\A') if begin_anchor
285
+ regexp_string.sub!(/\z/, '\\z') if end_anchor
270
286
  regexp = /#{regexp_string}/i
271
287
  matched_text =
272
288
  if (match = regexp.match(target))
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FatCore
4
4
  MAJOR = 4
5
- MINOR = 10
5
+ MINOR = 11
6
6
  PATCH = 0
7
7
 
8
8
  # FatCore version number
@@ -269,6 +269,21 @@ the people, for the people, shall not perish from the earth."
269
269
  expect('Hello:world'.fuzzy_match('hel:ox')).to be_falsy
270
270
  end
271
271
 
272
+ it 'requires end-anchor for ending colon' do
273
+ expect('Hello, to the world'.fuzzy_match('hel:world:')).to eq('Hello to the world')
274
+ expect('Hello, to the world today'.fuzzy_match('to:world:')).to be_nil
275
+ end
276
+
277
+ it 'requires start-anchor for leading colon' do
278
+ expect('Hello, to the world'.fuzzy_match(':hel:the')).to eq('Hello to the')
279
+ expect('Hello, to the world today'.fuzzy_match(':world:today')).to be_nil
280
+ end
281
+
282
+ it 'requires start-anchor and end-anchor for leading and ending colon' do
283
+ expect('Hello, to the world'.fuzzy_match(':hel:world:')).to eq('Hello to the world')
284
+ expect('Hello, to the world today'.fuzzy_match('hel:world:')).to be_falsy
285
+ end
286
+
272
287
  it 'should return the matched text' do
273
288
  expect('Hello:world'.fuzzy_match('hel')).to eq('Hel')
274
289
  expect('Hello:world'.fuzzy_match('hel:wor')).to eq('Hello:wor')
@@ -280,6 +295,9 @@ the people, for the people, shall not perish from the earth."
280
295
  expect('St Lukes'.fuzzy_match('st. luke\'s')).to eq('St Lukes')
281
296
  expect('St Lukes, Inc.'.fuzzy_match('st luke inc')).to eq('St Lukes Inc')
282
297
  expect('E*TRADE'.fuzzy_match('etrade')).to eq('ETRADE')
298
+ # Does not recognize non-alphanumerics as start of string.
299
+ expect('The 1 Dollar Store'.fuzzy_match('1 stor')).to be_truthy
300
+ expect('The $1 Dollar Store'.fuzzy_match('$1 stor')).to be_falsy
283
301
  end
284
302
  end
285
303
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.0
4
+ version: 4.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty