fat_core 4.8.3 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7185e045a281695d2f45f26e53d2614125dc0b8f8912e247008b1bafa2a3e98e
4
- data.tar.gz: 5ee7ed7308b1a5300f8eb278c00bbdd95ec04adc22c8e46e7743741a0d34df7b
3
+ metadata.gz: b4ec4463c5e5a2ba5718fea513be1cf2f01aba020205b05688a24b5e8d08c3a4
4
+ data.tar.gz: 4133d30f997f69bacacc5975c85deb7614b7c95571aea1166a02fd204c984169
5
5
  SHA512:
6
- metadata.gz: 2a1519d932d6f7409f1b4ec0e873836f675c9c77c1655ba0884d43fca62ba7209fca32dd6860e60e29ab9147ab8f8dde5cb1279a23ffc1517d73885e2dbd5fa1
7
- data.tar.gz: c740324e31d150b670cd940ffec4ed4394fe4223b8f951dff8838f176c39905b753d3dce8017f77477cd440ad171e3839d626d8b54e4cf8e00782516114b2850
6
+ metadata.gz: fb8fc88f40ca65406599bce7d26e4ef1d3b804369813ec708664c7ef3265fe03fc548066ed1bcae0639a2ea007e46bba352c838350ad5c8d16eabaeede02f092
7
+ data.tar.gz: e53428dd7cd1cf4ae7c532f455a5c9fc6ec8d106e5f60f7c0f46e621ee97126ae48954862485727a3c0abdc42f70bdeb5bb32587e5c29eca893edad268333546
data/.rubocop.yml CHANGED
@@ -1,3 +1,16 @@
1
- inherit_from:
2
- - '~/.rubocop.yml'
3
- - '.rubocop_todo.yml'
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.7
6
+ Exclude:
7
+ - 'test/tmp/**/*'
8
+ - 'vendor/bundle/**/*'
9
+
10
+ Style/MethodCallWithArgsParentheses:
11
+ Exclude:
12
+ - '**/Gemfile'
13
+
14
+ Style/ClassAndModuleChildren:
15
+ Exclude:
16
+ - 'test/**/*'
data/.travis.yml CHANGED
@@ -4,4 +4,4 @@ rvm:
4
4
  - 2.5
5
5
  - 2.6
6
6
  - 2.7
7
- - ruby-head
7
+ - 3.0
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'damerau-levenshtein', git: 'https://github.com/ddoherty03/damerau-levenshtein'
4
+ gem 'rubocop-shopify', require: false
4
5
 
5
6
  # Specify your gem's dependencies in fat_core.gemspec
6
7
  gemspec
data/lib/fat_core/all.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fat_core/array'
2
4
  require 'fat_core/bigdecimal'
3
5
  require 'fat_core/date'
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FatCore
2
4
  module Array
3
5
  # Return the index of the last element of this Array. This is just a
4
6
  # convenience for an oft-needed Array attribute.
5
7
  def last_i
6
- self.size - 1
8
+ size - 1
7
9
  end
8
10
 
9
11
  # Return a new Array that is the intersection of this Array with +other+,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bigdecimal'
2
4
 
3
5
  module FatCore
data/lib/fat_core/date.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require 'active_support/core_ext/date'
3
5
  require 'active_support/core_ext/time'
@@ -106,7 +108,7 @@ module FatCore
106
108
  # form.
107
109
  # @return [String]
108
110
  def american
109
- strftime '%-m/%-d/%Y'
111
+ strftime('%-m/%-d/%Y')
110
112
  end
111
113
 
112
114
  # :category: Queries
@@ -117,7 +119,7 @@ module FatCore
117
119
  # Self's calendar "half" by analogy to calendar quarters: 1 or 2, depending
118
120
  # on whether the date falls in the first or second half of the calendar
119
121
  # year.
120
- # @return [1, 2]
122
+ # @return [Integer]
121
123
  def half
122
124
  case month
123
125
  when (1..6)
@@ -131,7 +133,7 @@ module FatCore
131
133
 
132
134
  # Self's calendar quarter: 1, 2, 3, or 4, depending on which calendar quarter
133
135
  # the date falls in.
134
- # @return [1, 2, 3, 4]
136
+ # @return [Integer]
135
137
  def quarter
136
138
  case month
137
139
  when (1..3)
@@ -147,7 +149,7 @@ module FatCore
147
149
 
148
150
  # Self's calendar bimonth: 1, 2, 3, 4, 5, or 6 depending on which calendar
149
151
  # bimonth the date falls in.
150
- # @return [1, 2, 3, 4, 5, 6]
152
+ # @return [Integer]
151
153
  def bimonth
152
154
  case month
153
155
  when (1..2)
@@ -857,7 +859,7 @@ module FatCore
857
859
  ::Date.parse('2012-12-24'),
858
860
  # And Trump
859
861
  ::Date.parse('2018-12-24'),
860
- ::Date.parse('2019-12-24')
862
+ ::Date.parse('2019-12-24'),
861
863
  ].freeze
862
864
 
863
865
  # Presidential funeral since JFK
@@ -877,7 +879,7 @@ module FatCore
877
879
  # GTF Funeral
878
880
  ::Date.parse('2007-01-02'),
879
881
  # GHWBFuneral
880
- ::Date.parse('2018-12-05')
882
+ ::Date.parse('2018-12-05'),
881
883
  ].freeze
882
884
 
883
885
  # Return whether this date is a United States federal holiday.
@@ -1115,7 +1117,7 @@ module FatCore
1115
1117
  def nyse_workday?
1116
1118
  !nyse_holiday?
1117
1119
  end
1118
- alias trading_day? nyse_workday?
1120
+ alias_method :trading_day?, :nyse_workday?
1119
1121
 
1120
1122
  # Return the date that is n NYSE trading days after or before (if n < 0) this
1121
1123
  # date.
@@ -1134,7 +1136,7 @@ module FatCore
1134
1136
  end
1135
1137
  d
1136
1138
  end
1137
- alias add_trading_days add_nyse_workdays
1139
+ alias_method :add_trading_days, :add_nyse_workdays
1138
1140
 
1139
1141
  # Return the next NYSE trading day after this date. The date returned is always
1140
1142
  # a date at least one day after this date, never this date.
@@ -1143,7 +1145,7 @@ module FatCore
1143
1145
  def next_nyse_workday
1144
1146
  add_nyse_workdays(1)
1145
1147
  end
1146
- alias next_trading_day next_nyse_workday
1148
+ alias_method :next_trading_day, :next_nyse_workday
1147
1149
 
1148
1150
  # Return the last NYSE trading day before this date. The date returned is always
1149
1151
  # a date at least one day before this date, never this date.
@@ -1152,7 +1154,7 @@ module FatCore
1152
1154
  def prior_nyse_workday
1153
1155
  add_nyse_workdays(-1)
1154
1156
  end
1155
- alias prior_trading_day prior_nyse_workday
1157
+ alias_method :prior_trading_day, :prior_nyse_workday
1156
1158
 
1157
1159
  # Return this date if its a trading day, otherwise skip forward to the first
1158
1160
  # later trading day.
@@ -1212,11 +1214,15 @@ module FatCore
1212
1214
  # MLK's Birthday (Third Monday in Jan) since 1998
1213
1215
  year >= 1998 && nth_wday_in_month?(3, 1, 1)
1214
1216
  when 2
1215
- # Lincoln's birthday until 1953
1216
- # Washington's Birthday (Third Monday in Feb)
1217
- (year <= 1953 && month == 2 && day == 12) ||
1218
- (year <= 1970 ? (month == 2 && day == 22)
1219
- : nth_wday_in_month?(3, 1, 2))
1217
+ # Washington's Birthday was celebrated on February 22 until 1970. In
1218
+ # 1971 and later, it was moved to the third Monday in February. Note:
1219
+ # Lincoln's birthday is not an official holiday, but is sometimes
1220
+ # included with Washington's and called "Presidents' Day."
1221
+ if year <= 1970
1222
+ month == 2 && day == 22
1223
+ else
1224
+ nth_wday_in_month?(3, 1, 2)
1225
+ end
1220
1226
  when 3, 4
1221
1227
  # Good Friday
1222
1228
  if !friday?
@@ -1419,7 +1425,7 @@ module FatCore
1419
1425
  #
1420
1426
  # @param spec [String, #to_s] the spec to be interpreted as a calendar period
1421
1427
  #
1422
- # @param spec_type [:from, :to] return the first (:from) or last (:to)
1428
+ # @param spec_type [Symbol, :from, :to] return the first (:from) or last (:to)
1423
1429
  # date in the spec's period respectively
1424
1430
  #
1425
1431
  # @return [::Date] date that is the first (:from) or last (:to) in the period
@@ -1432,11 +1438,12 @@ module FatCore
1432
1438
 
1433
1439
  today = ::Date.current
1434
1440
  case spec.clean
1435
- when %r{\A(\d\d\d\d)[-/](\d\d?)[-/](\d\d?)\z}
1441
+ when %r{\A(?<yr>\d\d\d\d)[-/](?<mo>\d\d?)[-/](?<dy>\d\d?)\z}
1436
1442
  # A specified date
1437
- ::Date.new($1.to_i, $2.to_i, $3.to_i)
1438
- when /\AW(\d\d?)\z/, /\A(\d\d?)W\z/
1439
- week_num = $1.to_i
1443
+ ::Date.new(Regexp.last_match[:yr].to_i, Regexp.last_match[:mo].to_i,
1444
+ Regexp.last_match[:dy].to_i)
1445
+ when /\AW(?<wk>\d\d?)\z/, /\A(?<wk>\d\d?)W\z/
1446
+ week_num = Regexp.last_match[:wk].to_i
1440
1447
  if week_num < 1 || week_num > 53
1441
1448
  raise ArgumentError, "invalid week number (1-53): '#{spec}'"
1442
1449
  end
@@ -1446,9 +1453,9 @@ module FatCore
1446
1453
  else
1447
1454
  ::Date.commercial(today.year, week_num).end_of_week
1448
1455
  end
1449
- when %r{\A(\d\d\d\d)[-/]W(\d\d?)\z}, %r{\A(\d\d\d\d)[-/](\d\d?)W\z}
1450
- year = $1.to_i
1451
- week_num = $2.to_i
1456
+ when %r{\A(?<yr>\d\d\d\d)[-/]W(?<wk>\d\d?)\z}, %r{\A(?<yr>\d\d\d\d)[-/](?<wk>\d\d?)W\z}
1457
+ year = Regexp.last_match[:yr].to_i
1458
+ week_num = Regexp.last_match[:wk].to_i
1452
1459
  if week_num < 1 || week_num > 53
1453
1460
  raise ArgumentError, "invalid week number (1-53): '#{spec}'"
1454
1461
  end
@@ -1458,10 +1465,10 @@ module FatCore
1458
1465
  else
1459
1466
  ::Date.commercial(year, week_num).end_of_week
1460
1467
  end
1461
- when %r{^(\d\d\d\d)[-/](\d)[Qq]$}, %r{^(\d\d\d\d)[-/][Qq](\d)$}
1468
+ when %r{^(?<yr>\d\d\d\d)[-/](?<qt>\d)[Qq]$}, %r{^(?<yr>\d\d\d\d)[-/][Qq](?<qt>\d)$}
1462
1469
  # Year-Quarter
1463
- year = $1.to_i
1464
- quarter = $2.to_i
1470
+ year = Regexp.last_match[:yr].to_i
1471
+ quarter = Regexp.last_match[:qt].to_i
1465
1472
  unless [1, 2, 3, 4].include?(quarter)
1466
1473
  raise ArgumentError, "invalid quarter number (1-4): '#{spec}'"
1467
1474
  end
@@ -1472,10 +1479,10 @@ module FatCore
1472
1479
  else
1473
1480
  ::Date.new(year, month, 1).end_of_quarter
1474
1481
  end
1475
- when /^([1234])[qQ]$/, /^[qQ]([1234])$/
1482
+ when /^(?<qt>[1234])[qQ]$/, /^[qQ](?<qt>[1234])$/
1476
1483
  # Quarter only
1477
1484
  this_year = today.year
1478
- quarter = $1.to_i
1485
+ quarter = Regexp.last_match[:qt].to_i
1479
1486
  unless [1, 2, 3, 4].include?(quarter)
1480
1487
  raise ArgumentError, "invalid quarter number (1-4): '#{spec}'"
1481
1488
  end
@@ -1486,10 +1493,10 @@ module FatCore
1486
1493
  else
1487
1494
  date.end_of_quarter
1488
1495
  end
1489
- when %r{^(\d\d\d\d)[-/](\d)[Hh]$}, %r{^(\d\d\d\d)[-/][Hh](\d)$}
1496
+ when %r{^(?<yr>\d\d\d\d)[-/](?<hf>\d)[Hh]$}, %r{^(?<yr>\d\d\d\d)[-/][Hh](?<hf>\d)$}
1490
1497
  # Year-Half
1491
- year = $1.to_i
1492
- half = $2.to_i
1498
+ year = Regexp.last_match[:yr].to_i
1499
+ half = Regexp.last_match[:hf].to_i
1493
1500
  msg = "invalid half number: '#{spec}'"
1494
1501
  raise ArgumentError, msg unless [1, 2].include?(half)
1495
1502
 
@@ -1499,10 +1506,10 @@ module FatCore
1499
1506
  else
1500
1507
  ::Date.new(year, month, 1).end_of_half
1501
1508
  end
1502
- when /^([12])[hH]$/, /^[hH]([12])$/
1509
+ when /^(?<hf>[12])[hH]$/, /^[hH](?<hf>[12])$/
1503
1510
  # Half only
1504
1511
  this_year = today.year
1505
- half = $1.to_i
1512
+ half = Regexp.last_match[:hf].to_i
1506
1513
  msg = "invalid half number: '#{spec}'"
1507
1514
  raise ArgumentError, msg unless [1, 2].include?(half)
1508
1515
 
@@ -1512,10 +1519,10 @@ module FatCore
1512
1519
  else
1513
1520
  date.end_of_half
1514
1521
  end
1515
- when %r{^(\d\d\d\d)[-/](\d\d?)*$}
1522
+ when %r{^(?<yr>\d\d\d\d)[-/](?<mo>\d\d?)*$}
1516
1523
  # Year-Month only
1517
- year = $1.to_i
1518
- month = $2.to_i
1524
+ year = Regexp.last_match[:yr].to_i
1525
+ month = Regexp.last_match[:mo].to_i
1519
1526
  unless [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(month)
1520
1527
  raise ArgumentError, "invalid month number (1-12): '#{spec}'"
1521
1528
  end
@@ -1525,10 +1532,10 @@ module FatCore
1525
1532
  else
1526
1533
  ::Date.new(year, month, 1).end_of_month
1527
1534
  end
1528
- when %r{^(\d\d?)[-/](\d\d?)*$}
1535
+ when %r{^(?<mo>\d\d?)[-/](?<dy>\d\d?)*$}
1529
1536
  # Month-Day only
1530
- month = $1.to_i
1531
- day = $2.to_i
1537
+ month = Regexp.last_match[:mo].to_i
1538
+ day = Regexp.last_match[:dy].to_i
1532
1539
  unless [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(month)
1533
1540
  raise ArgumentError, "invalid month number (1-12): '#{spec}'"
1534
1541
  end
@@ -1538,9 +1545,9 @@ module FatCore
1538
1545
  else
1539
1546
  ::Date.new(today.year, month, day).end_of_month
1540
1547
  end
1541
- when /\A(\d\d?)\z/
1548
+ when /\A(?<mo>\d\d?)\z/
1542
1549
  # Month only
1543
- month = $1.to_i
1550
+ month = Regexp.last_match[:mo].to_i
1544
1551
  unless [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].include?(month)
1545
1552
  raise ArgumentError, "invalid month number (1-12): '#{spec}'"
1546
1553
  end
@@ -1550,12 +1557,13 @@ module FatCore
1550
1557
  else
1551
1558
  ::Date.new(today.year, month, 1).end_of_month
1552
1559
  end
1553
- when /^(\d\d\d\d)$/
1560
+ when /^(?<yr>\d\d\d\d)$/
1554
1561
  # Year only
1562
+ year = Regexp.last_match[:yr].to_i
1555
1563
  if spec_type == :from
1556
- ::Date.new($1.to_i, 1, 1)
1564
+ ::Date.new(year, 1, 1)
1557
1565
  else
1558
- ::Date.new($1.to_i, 12, 31)
1566
+ ::Date.new(year, 12, 31)
1559
1567
  end
1560
1568
  when /^(to|this_?)?day/
1561
1569
  today
@@ -1679,6 +1687,43 @@ module FatCore
1679
1687
  end
1680
1688
  end
1681
1689
 
1690
+ # Return the 1-indexed integer that corresponds to a month name.
1691
+ #
1692
+ # @param name [String] a name of a month
1693
+ #
1694
+ # @return [Integer] the integer integer that corresponds to a month
1695
+ # name, or nil of no month recognized.
1696
+ def mo_name_to_num(name)
1697
+ case name.clean
1698
+ when /\Ajan/i
1699
+ 1
1700
+ when /\Afeb/i
1701
+ 2
1702
+ when /\Amar/i
1703
+ 3
1704
+ when /\Aapr/i
1705
+ 4
1706
+ when /\Amay/i
1707
+ 5
1708
+ when /\Ajun/i
1709
+ 6
1710
+ when /\Ajul/i
1711
+ 7
1712
+ when /\Aaug/i
1713
+ 8
1714
+ when /\Asep/i
1715
+ 9
1716
+ when /\Aoct/i
1717
+ 10
1718
+ when /\Anov/i
1719
+ 11
1720
+ when /\Adec/i
1721
+ 12
1722
+ else
1723
+ nil
1724
+ end
1725
+ end
1726
+
1682
1727
  # Return the nth weekday in the given month. If n is negative, count from
1683
1728
  # last day of month.
1684
1729
  #
@@ -1744,8 +1789,8 @@ module FatCore
1744
1789
  # Ensure that date is of class Date based either on a string or Date
1745
1790
  # object.
1746
1791
  #
1747
- # @param dat [String|Date|Time] the object to be converted to Date
1748
- # @return [Date]
1792
+ # @param dat [String, Date, Time] the object to be converted to Date
1793
+ # @return [Date, DateTime]
1749
1794
  def ensure_date(dat)
1750
1795
  case dat
1751
1796
  when String
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Enumerable
2
4
  # Yield items in groups of n, for each group yield the group number, starting
3
5
  # with zero and an Array of n items, or all remaining items if less than n.
@@ -8,7 +10,10 @@ module Enumerable
8
10
  # end
9
11
  def groups_of(num)
10
12
  k = -1
11
- group_by { k += 1; k.div(num) }
13
+ group_by do
14
+ k += 1
15
+ k.div(num)
16
+ end
12
17
  end
13
18
 
14
19
  # Yield each item together with two booleans that indicate whether the item is
data/lib/fat_core/hash.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
1
4
  # The FatCore extensions to Hash provide a handful of generally useful methods
2
5
  # on Ruby Hash objects.
3
6
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fat_core/numeric'
2
4
 
3
5
  module Kernel
data/lib/fat_core/nil.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FatCore
2
4
  module NilClass
3
5
  # Allow nils to respond to #as_string like String and Symbol
@@ -6,7 +8,7 @@ module FatCore
6
8
  def as_string
7
9
  ''
8
10
  end
9
- alias entitle as_string
11
+ alias_method :entitle, :as_string
10
12
 
11
13
  # Allow nils to respond to #tex_quote for use in TeX documents
12
14
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fat_core/patches'
2
4
  require 'active_support/core_ext/object/blank'
3
5
 
@@ -74,11 +76,11 @@ module FatCore
74
76
  end
75
77
 
76
78
  # Break the number into parts; underscores are possible in all components.
77
- str =~ /\A([-+])?([\d_]*)((\.)?([\d_]*))?([eE][+-]?[\d_]+)?\z/
78
- sig = $1 || ''
79
- whole = $2 ? $2.delete('_') : ''
80
- frac = $5 || ''
81
- exp = $6 || ''
79
+ str =~ /\A(?<sg>[-+])?(?<wh>[\d_]*)((\.)?(?<fr>[\d_]*))?(?<ex>x[eE][+-]?[\d_]+)?\z/
80
+ sig = Regexp.last_match[:sg] || ''
81
+ whole = Regexp.last_match[:wh] ? Regexp.last_match[:wh].delete('_') : ''
82
+ frac = Regexp.last_match[:fr] || ''
83
+ exp = Regexp.last_match[:ex] || ''
82
84
 
83
85
  # Pad out the fractional part with zeroes to the right
84
86
  unless places.nil?
@@ -133,12 +135,13 @@ module FatCore
133
135
  mins, secs = divmod(60)
134
136
  hrs, mins = mins.divmod(60)
135
137
  if frac.round(5) > 0.0
136
- '%02<hrs>d:%02<mins>d:%02<secs>d.%<frac>d' % { hrs: hrs,
137
- mins: mins, secs: secs,
138
- frac: frac.round(5) * 100 }
138
+ format('%02<hrs>d:%02<mins>d:%02<secs>d.%<frac>d',
139
+ { hrs: hrs,
140
+ mins: mins, secs: secs,
141
+ frac: frac.round(5) * 100 })
139
142
  else
140
- '%02<hrs>d:%02<mins>d:%02<secs>d' % { hrs: hrs, mins: mins,
141
- secs: secs }
143
+ format('%02<hrs>d:%02<mins>d:%02<secs>d',
144
+ { hrs: hrs, mins: mins, secs: secs })
142
145
  end
143
146
  end
144
147
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Provide #positive? and #negative? for older versions of Ruby.
2
4
  unless 2.respond_to?(:positive?)
3
5
  # Patch Numeric
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # FatCore extends the Range class with methods that
2
4
  #
3
5
  # 1. provide some set operations operations on Ranges, union, intersection, and
@@ -130,7 +132,7 @@ module FatCore
130
132
 
131
133
  ([min, other.min].max..[max, other.max].min)
132
134
  end
133
- alias & intersection
135
+ alias_method :&, :intersection
134
136
 
135
137
  # Return a Range that represents the union between this range and the
136
138
  # `other` range. If there is no overlap and self is not contiguous with
@@ -148,13 +150,16 @@ module FatCore
148
150
 
149
151
  ([min, other.min].min..[max, other.max].max)
150
152
  end
151
- alias + union
153
+ alias_method :+, :union
152
154
 
153
155
  # The difference method, -, removes the overlapping part of the other
154
156
  # argument from self. Because in the case where self is a superset of the
155
157
  # other range, this will result in the difference being two non-contiguous
156
158
  # ranges, this returns an array of ranges. If there is no overlap or if
157
159
  # self is a subset of the other range, return an array of self
160
+ #
161
+ # @param other [Range] the Range whose overlap is removed from self
162
+ # @return [Array<Range>] the Ranges representing self with other removed
158
163
  def difference(other)
159
164
  unless max.respond_to?(:succ) && min.respond_to?(:pred) &&
160
165
  other.max.respond_to?(:succ) && other.min.respond_to?(:pred)
@@ -182,7 +187,7 @@ module FatCore
182
187
  [(min..isec.min.pred), (isec.max.succ..max)]
183
188
  end
184
189
  end
185
- alias - difference
190
+ alias_method :-, :difference
186
191
 
187
192
  # Allow erb or erubis documents to directly interpolate a Range.
188
193
  #
@@ -375,7 +380,7 @@ module FatCore
375
380
  # (4..8) <=> (4..8) #=> 0
376
381
  #
377
382
  # @param other [Range] range to compare self with
378
- # @return [-1, 0, 1] if self is less, equal, or greater than other
383
+ # @return [Integer, -1, 0, 1] if self is less, equal, or greater than other
379
384
  def <=>(other)
380
385
  [min, max] <=> other.minmax
381
386
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bigdecimal'
2
4
  require 'fat_core/patches'
3
5
  require 'damerau-levenshtein'
@@ -49,14 +51,14 @@ module FatCore
49
51
  #
50
52
  # @return [String] self wrapped
51
53
  def wrap(width = 70, hang = 0)
52
- result = ''
54
+ result = ::String.new
53
55
  first_line = true
54
56
  first_word_on_line = true
55
57
  line_width_so_far = 0
56
58
  words = split(' ')
57
59
  words.each do |w|
58
- w = ' ' * hang + w if !first_line && first_word_on_line
59
- w = ' ' + w unless first_word_on_line
60
+ w = ::String.new(' ') * hang + w if !first_line && first_word_on_line
61
+ w = ::String.new(' ') + w unless first_word_on_line
60
62
  result << w
61
63
  first_word_on_line = false
62
64
  line_width_so_far += 1 + w.length
@@ -104,8 +106,10 @@ module FatCore
104
106
  #
105
107
  # @return [Date] the translated Date
106
108
  def as_date
107
- if self =~ %r{(\d\d\d\d)[-/]?(\d\d?)[-/]?(\d\d?)}
108
- ::Date.new($1.to_i, $2.to_i, $3.to_i)
109
+ if self =~ %r{(?<yr>\d\d\d\d)[-/]?(?<mo>\d\d?)[-/]?(?<dy>\d\d?)}
110
+ ::Date.new(Regexp.last_match[:yr].to_i,
111
+ Regexp.last_match[:mo].to_i,
112
+ Regexp.last_match[:dy].to_i)
109
113
  end
110
114
  end
111
115
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fat_core/string'
2
4
 
3
5
  module FatCore
@@ -14,7 +16,7 @@ module FatCore
14
16
  def as_string
15
17
  to_s.tr('_', ' ').split(' ').join(' ').entitle
16
18
  end
17
- alias entitle as_string
19
+ alias_method :entitle, :as_string
18
20
 
19
21
  # Return self. This (together with String#as_sym) allows `#as_sym` to be
20
22
  # applied to a string or Symbol and get back a Symbol with out testing for
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FatCore
2
4
  MAJOR = 4
3
- MINOR = 8
4
- PATCH = 3
5
+ MINOR = 9
6
+ PATCH = 0
5
7
 
6
8
  # FatCore version number
7
9
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -425,6 +425,22 @@ describe Date do
425
425
  expect(Date.parse_spec('forever', :to)).to eq Date::EOT
426
426
  expect(Date.parse_spec('never')).to be_nil
427
427
  end
428
+
429
+ it 'should be able to convert a month name into its sequential number' do
430
+ expect(Date.mo_name_to_num(' January')).to eq 1
431
+ expect(Date.mo_name_to_num(' feb ')).to eq 2
432
+ expect(Date.mo_name_to_num(' mAr ')).to eq 3
433
+ expect(Date.mo_name_to_num(' Aprol ')).to eq 4
434
+ expect(Date.mo_name_to_num("\t \tmaybe")).to eq 5
435
+ expect(Date.mo_name_to_num("\t \tjunta\t \t")).to eq 6
436
+ expect(Date.mo_name_to_num("\t \tjulia\t \t")).to eq 7
437
+ expect(Date.mo_name_to_num("\t \tAugustus\t \t")).to eq 8
438
+ expect(Date.mo_name_to_num("September")).to eq 9
439
+ expect(Date.mo_name_to_num("octagon")).to eq 10
440
+ expect(Date.mo_name_to_num(" novena this month")).to eq 11
441
+ expect(Date.mo_name_to_num("decimal")).to eq 12
442
+ expect(Date.mo_name_to_num(" dewey decimal")).to be nil
443
+ end
428
444
  end
429
445
  end
430
446
 
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.8.3
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-07 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -218,7 +218,7 @@ licenses:
218
218
  - MIT
219
219
  metadata:
220
220
  yard.run: yri
221
- post_install_message:
221
+ post_install_message:
222
222
  rdoc_options: []
223
223
  require_paths:
224
224
  - lib
@@ -233,9 +233,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
- rubyforge_project:
237
- rubygems_version: 2.7.6.2
238
- signing_key:
236
+ rubygems_version: 3.2.3
237
+ signing_key:
239
238
  specification_version: 4
240
239
  summary: fat_core provides some useful core extensions
241
240
  test_files: