fat_core 4.14.0 → 4.17.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: 8346fec82bf15a334c820d144c1ca1dd1dced6caf277d422d7436d8acc802da4
4
- data.tar.gz: 9fd7625a54123c14e2b267d4e0edfd476ec3ed651a0206601146ac56eefb201b
3
+ metadata.gz: a535331fa37f8a1247eb587f0b2a4770c5e37f7f27f7c2cb850ea9f31b4bd1ca
4
+ data.tar.gz: b0644ff70137d300cc2f02cdefdfa1aa9857f6f333e000137dc8e8124f02d760
5
5
  SHA512:
6
- metadata.gz: 0c8af36daf08287547b58ff26f83ec7adec26e3e1965b98ff89cdc7d73befb0c1b7d7d2b36d13c59a9869d73264a07925a85f611e8a9e2f0027f8716e52123ba
7
- data.tar.gz: '082df1b45297258a2f313879da999dd19f74a353a69bdcd83343fc84221165f5f7a5c7bcbaea2248e9a1260b35312a1cb4544838872dfe24cfbd74ffe698283f'
6
+ metadata.gz: 7ee6dee2e096d81087efb0a8a517010738b609102892e8f32617ca780edca9ba129433e79ef19e6c9979a27f4e451b141d1291fdd7457ccdbf38cec6cca53331
7
+ data.tar.gz: dcf803b07f015dbb3846a13a4cb27122e185dfae6b7461345a4deaf1ff2cfb838cfb75f6a0d5ce61f2bb1299bc80b8b1023bf898e800369a54564d6f5001fe2c
data/README.org CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  * FatCore
4
4
 
5
- fat-core is a simple gem to collect core extensions and a few new classes that
6
- I find useful in multiple projects. The emphasis is on extending the Date
7
- class to make it more useful in financial applications.
5
+ ~fat-core~ is a simple gem to collect core extensions and a few new classes
6
+ that I find useful in multiple projects. The emphasis is on extending the
7
+ Date class to make it more useful in financial applications.
8
8
 
9
9
  ** Installation
10
10
 
@@ -267,8 +267,6 @@ Date.parse_american('9/22/1957') => 1957-09-22
267
267
  **** Weekdays in Month
268
268
 
269
269
  **** Easter
270
-
271
-
272
270
  The ~Date~ class extension adds two methods for determining whether a given
273
271
  date is a US federal holiday as defined by federal law, including such things
274
272
  as federal holidays established by executive decree:
@@ -329,7 +327,6 @@ coverage on one Range by an Array of other Ranges:
329
327
 
330
328
  **
331
329
  * Enumerable
332
-
333
330
  FatCore::Enumerable extends Enumerable with the ~#each_with_flags~ method that
334
331
  yields the elements of the Enumerable but also yields two booleans, ~first~ and
335
332
  ~last~ that are set to true on respectively, the first and last element of the
@@ -344,6 +341,13 @@ deletion (~#delete_with_value~) and for manipulating the keys
344
341
  provides ~#each_pair_with_flags~ as an analog to Enumerable's
345
342
  ~#each_with_flags~.
346
343
 
344
+ It also provides the shovel operator as a convenient alias for ~Hash#merge~,
345
+ so that
346
+
347
+ #+begin_src ruby :tangle no
348
+ {a: 'A', b: 'B', c: 'C'} << {c: 'CC', d: 'DD'} << {e: 'EEE'} => {a: 'A', b: 'B', c: 'CC', d: 'DD', e: 'EEE'}
349
+ #+end_src
350
+
347
351
  *** String
348
352
 
349
353
  FatCore::String has methods for performing matching of one string with another
data/lib/fat_core/date.rb CHANGED
@@ -50,7 +50,7 @@ require 'fat_core/patches'
50
50
  module FatCore
51
51
  module Date
52
52
  # Set the default beginning of week to Monday for commercial weeks.
53
- ::Date.beginning_of_week = :monday
53
+ # ::Date.beginning_of_week = :monday
54
54
 
55
55
  # Constant for Beginning of Time (BOT) outside the range of what we would ever
56
56
  # want to find in commercial situations.
@@ -525,9 +525,9 @@ module FatCore
525
525
  # @return [::Date]
526
526
  def beginning_of_biweek
527
527
  if cweek.odd?
528
- beginning_of_week(:monday)
528
+ beginning_of_week(::Date.beginning_of_week)
529
529
  else
530
- (self - 1.week).beginning_of_week(:monday)
530
+ (self - 1.week).beginning_of_week(::Date.beginning_of_week)
531
531
  end
532
532
  end
533
533
 
@@ -535,18 +535,18 @@ module FatCore
535
535
 
536
536
  # Return the date that is the last day of the commercial biweek in which
537
537
  # self falls. A biweek is a period of two commercial weeks starting with
538
- # an odd-numbered week and with each week starting in Monday and ending on
538
+ # an odd-numbered week and with each week starting on Monday and ending on
539
539
  # Sunday. So this will always return a Sunday in an even-numbered week.
540
540
  # In the last week of the year (if it is not part of next year's first
541
541
  # week) the end of the biweek will not extend beyond self's week, so that
542
542
  # week 1 of the following year will start a new biweek. @return [::Date]
543
543
  def end_of_biweek
544
- if cweek >= 52 && end_of_week(:monday).year > year
545
- end_of_week(:monday)
544
+ if cweek >= 52 && end_of_week(::Date.beginning_of_week).year > year
545
+ end_of_week(::Date.beginning_of_week)
546
546
  elsif cweek.odd?
547
- (self + 1.week).end_of_week(:monday)
547
+ (self + 1.week).end_of_week(::Date.beginning_of_week)
548
548
  else
549
- end_of_week(:monday)
549
+ end_of_week(::Date.beginning_of_week)
550
550
  end
551
551
  end
552
552
 
@@ -29,6 +29,9 @@ module Enumerable
29
29
  # end
30
30
  # end
31
31
  def each_with_flags
32
+ # Test for beginless range
33
+ return nil if is_a?(Range) && self.begin.nil?
34
+
32
35
  last_k = size - 1
33
36
  each_with_index do |v, k|
34
37
  first = k.zero?
data/lib/fat_core/hash.rb CHANGED
@@ -136,6 +136,10 @@ module FatCore
136
136
 
137
137
  to_a.each_with_index.map { |(_k, v), i| [new_keys[i], v] }.to_h
138
138
  end
139
+
140
+ def <<(other)
141
+ self.merge(other)
142
+ end
139
143
  end
140
144
  end
141
145
 
@@ -300,13 +300,13 @@ module FatCore
300
300
  # default and extend the modifier syntax to allow '/I' to indicate
301
301
  # case-sensitive. Without the surrounding '/', quote any Regexp
302
302
  # metacharacters in the string and return a Regexp that matches the string
303
- # literally.
303
+ # literally, but still make the Regexp case insensitive.
304
304
  #
305
305
  # @example
306
306
  # '/Hello/'.as_regexp #=> /Hello/i
307
307
  # '/Hello/I'.as_regexp #=> /Hello/
308
- # 'Hello'.as_regexp #=> /Hello/
309
- # 'Hello\b'.as_regexp #=> /Hello\\b/
308
+ # 'Hello'.as_regexp #=> /Hello/i
309
+ # 'Hello\b'.as_regexp #=> /Hello\\b/i
310
310
  #
311
311
  # @return [Regexp]
312
312
  def as_regexp
@@ -324,7 +324,7 @@ module FatCore
324
324
  # body = Regexp.quote(body) if REGEXP_META_CHARACTERS.include?(body)
325
325
  Regexp.new(body, flags)
326
326
  else
327
- Regexp.new(Regexp.quote(self))
327
+ Regexp.new(Regexp.quote(self), Regexp::IGNORECASE)
328
328
  end
329
329
  end
330
330
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FatCore
4
4
  MAJOR = 4
5
- MINOR = 14
5
+ MINOR = 17
6
6
  PATCH = 0
7
7
 
8
8
  # FatCore version number
@@ -31,4 +31,18 @@ describe Enumerable do
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ it 'returns nil enumerating a beginless Range' do
36
+ bless = (..100)
37
+ result = bless.each_with_flags { |l, first, last| 44 }
38
+ expect(result).to be nil
39
+ end
40
+
41
+ it 'enumerates an endless Range' do
42
+ eless = (1..)
43
+ num = 0
44
+ eless.each_with_flags { |i, first, last| num += i; break if i >= 100 }
45
+ # Look at me, I'm Gauss
46
+ expect(num).to eq(5050)
47
+ end
34
48
  end
@@ -22,4 +22,11 @@ describe Hash do
22
22
  remap = { :a => :d }
23
23
  expect(hh.remap_keys(remap)).to eq({ :d => 1, :b => 2, :c => 1 })
24
24
  end
25
+
26
+ it 'make << an alias for Hash#merge' do
27
+ h1 = { a: 'A', b: 'B', c: 'C' }
28
+ h2 = { b: 'BB', d: 'DD' }
29
+ h3 = { e: 'EEE' }
30
+ expect(h1 << h2 << h3).to eq({ a: 'A', b: 'BB', c: 'C', d: 'DD', e: 'EEE' })
31
+ end
25
32
  end
@@ -167,16 +167,16 @@ the people, for the people, shall not perish from the earth."}
167
167
  expect(re.multiline?).to be true
168
168
  expect(re.match?('Hello WorlD')).to be false
169
169
 
170
- # Works without /../ but takes meta-characters literally
170
+ # Works without /../ but takes meta-characters literally, but still case insensitive
171
171
  str = "hello((\s+)(world))?"
172
172
  re = str.as_regexp
173
173
  expect(re.class).to eq Regexp
174
- expect(re.casefold?).to be false
174
+ expect(re.casefold?).to be true
175
175
  expect(re.multiline?).to be false
176
176
  expect(re.match?('hello world')).to be false
177
177
  expect(re.match?(str)).to be true
178
- expect('Hello\b'.as_regexp).to eq(/Hello\\b/)
179
- expect('Hello'.as_regexp).to eq(/Hello/)
178
+ expect('Hello\b'.as_regexp).to eq(/Hello\\b/i)
179
+ expect('Hello'.as_regexp).to eq(/Hello/i)
180
180
  end
181
181
 
182
182
  it 'converts metacharacters into Regexp' do
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.14.0
4
+ version: 4.17.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: 2023-05-09 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubygems_version: 3.4.9
242
+ rubygems_version: 3.4.10
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: some useful core extensions