fat_core 4.9.2 → 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 +4 -4
- data/.rubocop.yml +3 -0
- data/.simplecov +18 -0
- data/fat_core.gemspec +3 -3
- data/lib/fat_core/date.rb +4 -1
- data/lib/fat_core/numeric.rb +1 -1
- data/lib/fat_core/range.rb +1 -1
- data/lib/fat_core/string.rb +22 -6
- data/lib/fat_core/version.rb +2 -2
- data/lib/fat_core.rb +1 -0
- data/spec/lib/date_spec.rb +32 -5
- data/spec/lib/string_spec.rb +23 -5
- data/spec/spec_helper.rb +1 -2
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8607195b8f5ef6d04df1f438fbd59d3a22ca3a730d0d5bb9430ff37166d07174
|
4
|
+
data.tar.gz: e86aedc2aafebf6fc02efdf6f3f35f39ad93059b08a8bc4e635190e5964f2942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94983a4893c2c4882b360236f488c3a741ea8927488a69785ae4a7cc8f93612e11aa1f6899b359fcc2bb25742d6f062d3c76f5cbd75dfc64c24edba44be45755
|
7
|
+
data.tar.gz: 9700b48e6c73ec9ec49ed7da22679b4ea90676be71011b4c4c912cb4b53c2d613bb1712b8c59f440990570a33ffe12ab51ec0986ace906638408b3bab85f59d9
|
data/.rubocop.yml
CHANGED
data/.simplecov
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
# any custom configs like groups and filters can be here at a central place
|
5
|
+
add_filter '/spec/'
|
6
|
+
add_filter '/tmp/'
|
7
|
+
add_group "Models", "lib/fat_core"
|
8
|
+
# add_group "Core Extension", "lib/ext"
|
9
|
+
# After this many seconds between runs, old coverage stats are thrown out,
|
10
|
+
# so 3600 => 1 hour
|
11
|
+
merge_timeout 3600
|
12
|
+
# Make this true to merge rspec and cucumber coverage together
|
13
|
+
use_merging false
|
14
|
+
command_name 'Rspec'
|
15
|
+
nocov_token 'no_cover'
|
16
|
+
# Branch coverage
|
17
|
+
enable_coverage :branch
|
18
|
+
end
|
data/fat_core.gemspec
CHANGED
@@ -24,14 +24,14 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_development_dependency 'simplecov'
|
26
26
|
spec.add_development_dependency 'bundler'
|
27
|
+
spec.add_development_dependency 'debug', '>= 1.0.0'
|
27
28
|
spec.add_development_dependency 'rake'
|
28
29
|
spec.add_development_dependency 'rspec'
|
29
|
-
spec.add_development_dependency 'byebug'
|
30
30
|
spec.add_development_dependency 'pry'
|
31
31
|
spec.add_development_dependency 'pry-doc'
|
32
|
-
spec.add_development_dependency 'pry-byebug'
|
33
32
|
spec.add_development_dependency 'redcarpet'
|
33
|
+
spec.add_development_dependency 'solargraph'
|
34
34
|
|
35
|
-
spec.add_runtime_dependency 'activesupport'
|
35
|
+
spec.add_runtime_dependency 'activesupport', '~>6.0'
|
36
36
|
spec.add_runtime_dependency 'damerau-levenshtein'
|
37
37
|
end
|
data/lib/fat_core/date.rb
CHANGED
@@ -48,6 +48,9 @@ require 'fat_core/patches'
|
|
48
48
|
# the NYSE was closed for special reasons, such as the 9-11 attacks in 2001.
|
49
49
|
module FatCore
|
50
50
|
module Date
|
51
|
+
# Set the default beginning of week to Monday for commercial weeks.
|
52
|
+
::Date.beginning_of_week = :monday
|
53
|
+
|
51
54
|
# Constant for Beginning of Time (BOT) outside the range of what we would ever
|
52
55
|
# want to find in commercial situations.
|
53
56
|
BOT = ::Date.parse('1900-01-01')
|
@@ -70,7 +73,7 @@ module FatCore
|
|
70
73
|
# Format date to TeX documents as ISO strings but with en-dashes
|
71
74
|
# @return [String]
|
72
75
|
def tex_quote
|
73
|
-
strftime('%Y--%m--%d')
|
76
|
+
strftime('%Y--%m--%d').tex_quote
|
74
77
|
end
|
75
78
|
|
76
79
|
# :category: Formatting
|
data/lib/fat_core/numeric.rb
CHANGED
data/lib/fat_core/range.rb
CHANGED
data/lib/fat_core/string.rb
CHANGED
@@ -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
|
249
|
-
# expression, that is, match anything in self,
|
250
|
-
# 3.
|
251
|
-
#
|
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
|
-
regexp_string = matchers.map { |m| "
|
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))
|
data/lib/fat_core/version.rb
CHANGED
data/lib/fat_core.rb
CHANGED
data/spec/lib/date_spec.rb
CHANGED
@@ -586,7 +586,7 @@ describe Date do
|
|
586
586
|
.to be_end_of_semimonth
|
587
587
|
end
|
588
588
|
|
589
|
-
it '
|
589
|
+
it 'knows about biweeks' do
|
590
590
|
expect(Date.parse('2013-11-07').beginning_of_biweek)
|
591
591
|
.to eq Date.parse('2013-11-04')
|
592
592
|
expect(Date.parse('2013-11-07').end_of_biweek)
|
@@ -599,16 +599,23 @@ describe Date do
|
|
599
599
|
.to eq Date.parse('2010-01-03')
|
600
600
|
end
|
601
601
|
|
602
|
-
it '
|
602
|
+
it 'knows that a Monday is the beginning of the week' do
|
603
|
+
# A Monday
|
603
604
|
expect(Date.parse('2013-11-04')).to be_beginning_of_week
|
604
|
-
expect(Date.parse('2013-11-10')).to be_end_of_week
|
605
605
|
expect(Date.parse('2013-12-02')).to be_beginning_of_week
|
606
|
-
|
606
|
+
# A Sunday
|
607
607
|
expect(Date.parse('2013-10-13')).to_not be_beginning_of_week
|
608
|
+
end
|
609
|
+
|
610
|
+
it 'knows that a Sunday is the end of the week' do
|
611
|
+
# A Sunday
|
612
|
+
expect(Date.parse('2013-11-10')).to be_end_of_week
|
613
|
+
expect(Date.parse('2013-12-08')).to be_end_of_week
|
614
|
+
# A Saturday
|
608
615
|
expect(Date.parse('2013-10-19')).to_not be_end_of_week
|
609
616
|
end
|
610
617
|
|
611
|
-
it 'should know the beginning of chunks' do
|
618
|
+
it 'should know the beginning of non-week chunks' do
|
612
619
|
expect(Date.parse('2013-11-04').beginning_of_chunk(:year))
|
613
620
|
.to eq Date.parse('2013-01-01')
|
614
621
|
expect(Date.parse('2013-11-04').beginning_of_chunk(:half))
|
@@ -623,10 +630,30 @@ describe Date do
|
|
623
630
|
.to eq Date.parse('2013-11-01')
|
624
631
|
expect(Date.parse('2013-11-24').beginning_of_chunk(:semimonth))
|
625
632
|
.to eq Date.parse('2013-11-16')
|
633
|
+
end
|
634
|
+
|
635
|
+
it 'knows the beginning and end of bi-week-based chunks' do
|
636
|
+
# First Friday to prior Monday
|
626
637
|
expect(Date.parse('2013-11-08').beginning_of_chunk(:biweek))
|
627
638
|
.to eq Date.parse('2013-11-04')
|
639
|
+
# Second Wednesday to 2 prior Monday
|
640
|
+
expect(Date.parse('2013-11-13').beginning_of_chunk(:biweek))
|
641
|
+
.to eq Date.parse('2013-11-04')
|
642
|
+
end
|
643
|
+
|
644
|
+
it 'knows the beginning and end of week-based chunks' do
|
645
|
+
# A Friday to prior Monday
|
628
646
|
expect(Date.parse('2013-11-08').beginning_of_chunk(:week))
|
629
647
|
.to eq Date.parse('2013-11-04')
|
648
|
+
# A Friday to following Sunday
|
649
|
+
expect(Date.parse('2013-11-08').end_of_chunk(:week))
|
650
|
+
.to eq Date.parse('2013-11-10')
|
651
|
+
# A Sunday to prior Monday
|
652
|
+
expect(Date.parse('2013-11-10').beginning_of_chunk(:week))
|
653
|
+
.to eq Date.parse('2013-11-04')
|
654
|
+
# A Sunday to itself
|
655
|
+
expect(Date.parse('2013-11-10').end_of_chunk(:week))
|
656
|
+
.to eq Date.parse('2013-11-10')
|
630
657
|
expect {
|
631
658
|
Date.parse('2013-11-04').beginning_of_chunk(:wek)
|
632
659
|
}.to raise_error(ArgumentError)
|
data/spec/lib/string_spec.rb
CHANGED
@@ -245,7 +245,7 @@ the people, for the people, shall not perish from the earth."
|
|
245
245
|
|
246
246
|
describe 'Matching' do
|
247
247
|
it 'should be able to fuzzy match with another string' do
|
248
|
-
expect('Hello, world'.fuzzy_match('
|
248
|
+
expect('Hello, world'.fuzzy_match('wor')).to be_truthy
|
249
249
|
expect('Hello, world'.fuzzy_match('ox')).to be_falsy
|
250
250
|
end
|
251
251
|
|
@@ -255,23 +255,38 @@ the people, for the people, shall not perish from the earth."
|
|
255
255
|
end
|
256
256
|
|
257
257
|
it 'should be able to fuzzy match space-separated parts' do
|
258
|
-
expect('Hello world'.fuzzy_match('hel
|
258
|
+
expect('Hello world'.fuzzy_match('hel wor')).to be_truthy
|
259
259
|
expect('Hello, world'.fuzzy_match('hel ox')).to be_falsy
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should be able to fuzzy match colon-separated parts' do
|
263
|
-
expect('Hello:world'.fuzzy_match('hel:
|
263
|
+
expect('Hello:world'.fuzzy_match('hel:wor')).to be_truthy
|
264
264
|
expect('Hello:world'.fuzzy_match('hel:ox')).to be_falsy
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'should be able to fuzzy match colon-separated parts' do
|
268
|
-
expect('Hello:world'.fuzzy_match('hel:
|
268
|
+
expect('Hello:world'.fuzzy_match('hel:wor')).to be_truthy
|
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
|
-
expect('Hello:world'.fuzzy_match('hel:
|
289
|
+
expect('Hello:world'.fuzzy_match('hel:wor')).to eq('Hello:wor')
|
275
290
|
expect('Hello:world'.matches_with('/^h.*r/')).to eq('Hello:wor')
|
276
291
|
end
|
277
292
|
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
SimpleCov.command_name 'Rspec'
|
3
|
-
SimpleCov.start
|
4
3
|
|
5
4
|
require 'bundler/setup'
|
6
5
|
Bundler.setup
|
7
6
|
|
8
7
|
require 'pry'
|
9
|
-
require '
|
8
|
+
require 'debug'
|
10
9
|
|
11
10
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
12
11
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
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: 4.
|
4
|
+
version: 4.11.0
|
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:
|
11
|
+
date: 2022-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -39,21 +39,21 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: debug
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: redcarpet
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: solargraph
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: activesupport
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
145
|
+
version: '6.0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
152
|
+
version: '6.0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: damerau-levenshtein
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- ".gitignore"
|
176
176
|
- ".rspec"
|
177
177
|
- ".rubocop.yml"
|
178
|
+
- ".simplecov"
|
178
179
|
- ".travis.yml"
|
179
180
|
- ".yardopts"
|
180
181
|
- Gemfile
|
@@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
234
|
- !ruby/object:Gem::Version
|
234
235
|
version: '0'
|
235
236
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
237
|
+
rubygems_version: 3.3.3
|
237
238
|
signing_key:
|
238
239
|
specification_version: 4
|
239
240
|
summary: fat_core provides some useful core extensions
|