fat_core 4.12.0 → 4.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -15
- data/fat_core.gemspec +9 -5
- data/lib/fat_core/string.rb +6 -67
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/array_spec.rb +1 -1
- data/spec/lib/bigdecimal_spec.rb +1 -1
- data/spec/lib/date_spec.rb +708 -709
- data/spec/lib/enumerable_spec.rb +8 -8
- data/spec/lib/hash_spec.rb +3 -3
- data/spec/lib/kernel_spec.rb +1 -1
- data/spec/lib/nil_spec.rb +3 -3
- data/spec/lib/numeric_spec.rb +10 -10
- data/spec/lib/range_spec.rb +39 -39
- data/spec/lib/string_spec.rb +137 -129
- data/spec/lib/symbol_spec.rb +3 -3
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4634231d8dd0ed3baf9fd4d232e3e40adb777008b6b8299a5b5574466e10637
|
4
|
+
data.tar.gz: 4d8a1e46fa3e5ebb1014dedd75b801210921aa87ba1e01dba779cc62b4d01ca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d83fd2e04a0c1a466ae1ba75fcb888621a76ddfc9fa9f1cb78c1d05d3f1493bd347fd21e96f9f94ce14c8ddf9886ca98bbc32efc7c3f72200e9920a1dce4f49
|
7
|
+
data.tar.gz: 8de95683c4f0f969b7778dfce4e1235b2cd9838ebab6125880a3bdd099c631274f7f23e98a4e82696cb8ac50da8071383fc4d5eea5d4ce749c38a79ae399e2da
|
data/.rubocop.yml
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
inherit_from:
|
2
|
+
- ~/.rubocop.yml
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Exclude:
|
7
|
-
- 'test/tmp/**/*'
|
8
|
-
- 'vendor/bundle/**/*'
|
4
|
+
# inherit_gem:
|
5
|
+
# rubocop-shopify: rubocop.yml
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
- '**/Gemfile'
|
7
|
+
# require:
|
8
|
+
# - rubocop-rspec
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
# AllCops:
|
11
|
+
# TargetRubyVersion: 2.7
|
12
|
+
# Exclude:
|
13
|
+
# - 'test/tmp/**/*'
|
14
|
+
# - 'vendor/bundle/**/*'
|
17
15
|
|
18
|
-
Style/
|
19
|
-
|
16
|
+
# Style/MethodCallWithArgsParentheses:
|
17
|
+
# Exclude:
|
18
|
+
# - '**/Gemfile'
|
19
|
+
|
20
|
+
# Style/ClassAndModuleChildren:
|
21
|
+
# Exclude:
|
22
|
+
# - 'test/**/*'
|
23
|
+
|
24
|
+
# Style/StringLiterals:
|
25
|
+
# Enabled: false
|
data/fat_core.gemspec
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'fat_core/version'
|
3
|
+
require_relative 'lib/fat_core/version'
|
6
4
|
|
7
5
|
Gem::Specification.new do |spec|
|
8
6
|
spec.name = 'fat_core'
|
9
7
|
spec.version = FatCore::VERSION
|
10
8
|
spec.authors = ['Daniel E. Doherty']
|
11
9
|
spec.email = ['ded@ddoherty.net']
|
12
|
-
spec.summary = '
|
13
|
-
spec.description =
|
10
|
+
spec.summary = 'some useful core extensions'
|
11
|
+
spec.description = <<~DESC
|
12
|
+
Useful extensions to Date, String, Range and other classes
|
13
|
+
including useful Date extensions for dealing with US Federal
|
14
|
+
and New York Stock Exchange holidays and working days, a useful
|
15
|
+
Enumerable#each_with_flags for flagging first and last items in the
|
16
|
+
iteration, (also for Hash), set operations on Ranges
|
17
|
+
DESC
|
14
18
|
spec.homepage = 'https://github.com/ddoherty03/fat_core.git'
|
15
19
|
spec.license = 'MIT'
|
16
20
|
spec.required_ruby_version = '>= 2.2.2'
|
data/lib/fat_core/string.rb
CHANGED
@@ -4,6 +4,7 @@ require 'bigdecimal'
|
|
4
4
|
require 'fat_core/patches'
|
5
5
|
require 'damerau-levenshtein'
|
6
6
|
require 'active_support/core_ext/regexp'
|
7
|
+
require_relative 'numeric'
|
7
8
|
|
8
9
|
module FatCore
|
9
10
|
module String
|
@@ -245,8 +246,9 @@ module FatCore
|
|
245
246
|
#
|
246
247
|
# 1. Remove all periods, commas, apostrophes, and asterisks (the punctuation
|
247
248
|
# characters) from both self and `matcher`,
|
248
|
-
# 2. Treat internal ':' in the matcher as the equivalent of
|
249
|
-
# regular expression, that is, match
|
249
|
+
# 2. Treat internal ':stuff' in the matcher as the equivalent of
|
250
|
+
# '\bstuff.*?\b' in a regular expression, that is, match any word
|
251
|
+
# starting with stuff in self,
|
250
252
|
# 3. Treat leading ':' in the matcher as anchoring the match to the
|
251
253
|
# beginning of the target string,
|
252
254
|
# 4. Treat ending ':' in the matcher as anchoring the match to the
|
@@ -278,7 +280,7 @@ module FatCore
|
|
278
280
|
end
|
279
281
|
target = gsub(/[\*.,']/, '')
|
280
282
|
matchers = matcher.split(/[: ]+/)
|
281
|
-
regexp_string = matchers.map { |m| ".*?\\b#{Regexp.escape(m)}.*?" }.join('
|
283
|
+
regexp_string = matchers.map { |m| ".*?\\b#{Regexp.escape(m)}.*?" }.join('\\b')
|
282
284
|
regexp_string.sub!(/^\.\*\?/, '')
|
283
285
|
regexp_string.sub!(/\.\*\?$/, '')
|
284
286
|
regexp_string.sub!(/\A/, '\\A') if begin_anchor
|
@@ -364,70 +366,7 @@ module FatCore
|
|
364
366
|
numeric_re = /\A([-+])?([\d_]*)((\.)?([\d_]*))?([eE][+-]?[\d_]+)?\z/
|
365
367
|
return self unless clean =~ numeric_re
|
366
368
|
|
367
|
-
|
368
|
-
whole = $2 ? $2.delete('_') : ''
|
369
|
-
frac = $5 || ''
|
370
|
-
exp = $6 || ''
|
371
|
-
|
372
|
-
# Round frac or whole if places given. For positve places, round fraction
|
373
|
-
# to that many places; for negative, round the whole-number part to the
|
374
|
-
# absolute value of places left of the decimal.
|
375
|
-
if places
|
376
|
-
new_frac = frac.dup
|
377
|
-
new_whole = whole.dup
|
378
|
-
if places.zero?
|
379
|
-
new_frac = ''
|
380
|
-
elsif places.positive? && places < frac.length
|
381
|
-
new_frac = frac[0...places - 1]
|
382
|
-
new_frac[places - 1] =
|
383
|
-
if frac[places].to_i >= 5
|
384
|
-
(frac[places - 1].to_i + 1).to_s
|
385
|
-
else
|
386
|
-
frac[places - 1]
|
387
|
-
end
|
388
|
-
elsif places >= frac.length
|
389
|
-
new_frac = frac + '0' * (places - frac.length)
|
390
|
-
else
|
391
|
-
# Negative places, round whole to places.abs from decimal
|
392
|
-
places = places.abs
|
393
|
-
if places > whole.length
|
394
|
-
lead = whole[0].to_i >= 5 ? '1' : '0'
|
395
|
-
new_whole[0] = places == whole.length + 1 ? lead : '0'
|
396
|
-
new_whole[1..-1] = '0' * (places - 1)
|
397
|
-
new_frac = ''
|
398
|
-
elsif places > 1
|
399
|
-
target = whole.length - places
|
400
|
-
new_whole[target] =
|
401
|
-
if whole[target + 1].to_i >= 5
|
402
|
-
(whole[target].to_i + 1).to_s
|
403
|
-
else
|
404
|
-
whole[target]
|
405
|
-
end
|
406
|
-
new_whole[target + 1..whole.length - 1] =
|
407
|
-
'0' * (whole.length - target - 1)
|
408
|
-
new_frac = ''
|
409
|
-
else
|
410
|
-
# Rounding to 1 place, therefore, no rounding
|
411
|
-
new_frac = ''
|
412
|
-
new_whole = whole
|
413
|
-
end
|
414
|
-
end
|
415
|
-
frac = new_frac
|
416
|
-
whole = new_whole
|
417
|
-
end
|
418
|
-
|
419
|
-
# Place the commas in the whole part only
|
420
|
-
whole = whole.reverse
|
421
|
-
whole.gsub!(/([0-9]{3})/, '\\1,')
|
422
|
-
whole.gsub!(/,$/, '')
|
423
|
-
whole.reverse!
|
424
|
-
|
425
|
-
# Reassemble
|
426
|
-
if frac.blank?
|
427
|
-
sig + whole + exp
|
428
|
-
else
|
429
|
-
sig + whole + '.' + frac + exp
|
430
|
-
end
|
369
|
+
to_f.commas(places)
|
431
370
|
end
|
432
371
|
|
433
372
|
module ClassMethods
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/array_spec.rb
CHANGED
data/spec/lib/bigdecimal_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'fat_core/bigdecimal'
|
3
3
|
|
4
4
|
describe BigDecimal do
|
5
|
-
it '
|
5
|
+
it 'provides a human-readable inspect for BigDecimal' do
|
6
6
|
expect(BigDecimal('33.45').inspect).to eq '33.45'
|
7
7
|
end
|
8
8
|
end
|