fat_core 4.17.0 → 5.0.1
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/.envrc +1 -0
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/lib/fat_core/array.rb +52 -8
- data/lib/fat_core/date.rb +3 -3
- data/lib/fat_core/enumerable.rb +1 -0
- data/lib/fat_core/hash.rb +16 -18
- data/lib/fat_core/nil.rb +1 -1
- data/lib/fat_core/range.rb +9 -9
- data/lib/fat_core/string.rb +8 -8
- data/lib/fat_core/symbol.rb +2 -2
- data/lib/fat_core/version.rb +3 -3
- data/spec/lib/array_spec.rb +56 -14
- data/spec/lib/date_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d724c4622fd2432d363899d8d07f4e8f413f31c26f14b8b90f440a44196ccfda
|
4
|
+
data.tar.gz: 727fe3e1dfe0874244e2f9afa0f6fe6a20245f9a27893c785dd6ffb1452aee8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d314596c63838493e56820c8c2b1f8c26404b1d43fe66c476229019f4332994f9908dfa05d1fc4e1356a93b3cdd9a093065018ad81a6da6c53951886f4a8de9c
|
7
|
+
data.tar.gz: 4dd95124917667579d7b4dc7f709c5712b0cb6cddac6c0155dd9d2f44bac7a5c1127c5c6e9bb09d37d5c9d1be4da754682d2585dfea979b49270ee2cd4b31b37
|
data/.envrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PATH_add .bundle/bin
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/lib/fat_core/array.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module FatCore
|
4
|
+
# Useful extensions to the core Array class.
|
4
5
|
module Array
|
5
6
|
# Return the index of the last element of this Array. This is just a
|
6
7
|
# convenience for an oft-needed Array attribute.
|
@@ -8,14 +9,14 @@ module FatCore
|
|
8
9
|
size - 1
|
9
10
|
end
|
10
11
|
|
11
|
-
# Return a new Array that is the intersection of this Array with
|
12
|
-
# but without removing duplicates as the Array#& method
|
13
|
-
# this Array are included in the result but only if
|
14
|
-
#
|
15
|
-
def
|
12
|
+
# Return a new Array that is the intersection of this Array with all
|
13
|
+
# +others+, but without removing duplicates as the Array#& method
|
14
|
+
# does. All items of this Array are included in the result but only if
|
15
|
+
# they also appear in all of the other Arrays.
|
16
|
+
def intersect_with_dups(*others)
|
16
17
|
result = []
|
17
18
|
each do |itm|
|
18
|
-
result << itm if
|
19
|
+
result << itm if others.all? { |oth| oth.include?(itm) }
|
19
20
|
end
|
20
21
|
result
|
21
22
|
end
|
@@ -24,10 +25,53 @@ module FatCore
|
|
24
25
|
# without removing duplicates as the Array#- method does. All items of this
|
25
26
|
# Array are included in the result unless they also appear in the +other+
|
26
27
|
# Array.
|
27
|
-
def
|
28
|
+
def diff_with_dups(*others)
|
28
29
|
result = []
|
29
30
|
each do |itm|
|
30
|
-
result << itm
|
31
|
+
result << itm if others.none? { |oth| oth.include?(itm) }
|
32
|
+
end
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
# Convert this array into a single string by (1) applying #to_s to each
|
37
|
+
# element and (2) joining the elements with the string given by the sep:
|
38
|
+
# paramater. By default the sep parameter is ', '. You may use a different
|
39
|
+
# separation string in the case when there are only two items in the list
|
40
|
+
# by supplying a two_sep parameter. You may also supply a difference
|
41
|
+
# separation string to separate the second-last and last items in the
|
42
|
+
# array by supplying a last_sep: parameter. By default, the sep parameter
|
43
|
+
# is the string ', ', the two_sep is ' and ', and the last_sep is ', and
|
44
|
+
# ', all of which makes for a well-punctuated English clause. If sep is
|
45
|
+
# given, the other two parameters are set to its value by default. If
|
46
|
+
# last_sep is given, two_sep takes its value by default. If the input
|
47
|
+
# array is empty, #comma_join returns an empty string.
|
48
|
+
def comma_join(sep: nil, last_sep: nil, two_sep: nil)
|
49
|
+
orig_sep = sep
|
50
|
+
orig_last_sep = last_sep
|
51
|
+
sep ||= ', '
|
52
|
+
last_sep ||= orig_sep || ', and '
|
53
|
+
two_sep ||= orig_sep || orig_last_sep || ' and '
|
54
|
+
result = +''
|
55
|
+
case size
|
56
|
+
when 0
|
57
|
+
result
|
58
|
+
when 1
|
59
|
+
result = self[0].to_s
|
60
|
+
when 2
|
61
|
+
result = self[0].to_s + two_sep + self[1]
|
62
|
+
else
|
63
|
+
second_last = size - 2
|
64
|
+
last = size - 1
|
65
|
+
each_with_index do |itm, k|
|
66
|
+
result <<
|
67
|
+
if k == second_last
|
68
|
+
"#{itm}#{last_sep}"
|
69
|
+
elsif k == last
|
70
|
+
itm.to_s
|
71
|
+
else
|
72
|
+
"#{itm}#{sep}"
|
73
|
+
end
|
74
|
+
end
|
31
75
|
end
|
32
76
|
result
|
33
77
|
end
|
data/lib/fat_core/date.rb
CHANGED
@@ -90,7 +90,7 @@ module FatCore
|
|
90
90
|
# Format as an inactive Org date timestamp of the form `[YYYY-MM-DD <dow>]`
|
91
91
|
# (see Emacs org-mode)
|
92
92
|
# @return [String]
|
93
|
-
def org(active
|
93
|
+
def org(active: false)
|
94
94
|
if active
|
95
95
|
strftime('<%Y-%m-%d %a>')
|
96
96
|
else
|
@@ -186,7 +186,7 @@ module FatCore
|
|
186
186
|
# semimonth the date falls in.
|
187
187
|
# @return [Integer]
|
188
188
|
def semimonth
|
189
|
-
(month - 1) * 2 + (day <= 15 ? 1 : 2)
|
189
|
+
((month - 1) * 2) + (day <= 15 ? 1 : 2)
|
190
190
|
end
|
191
191
|
|
192
192
|
# Self's calendar biweek: 1, through 24 depending on which calendar
|
@@ -428,7 +428,7 @@ module FatCore
|
|
428
428
|
self - 1.day
|
429
429
|
end
|
430
430
|
|
431
|
-
#
|
431
|
+
# NOTE: the ::Date class already has a #succ method.
|
432
432
|
|
433
433
|
# The date that is the first day of the half-year in which self falls.
|
434
434
|
# @return [::Date]
|
data/lib/fat_core/enumerable.rb
CHANGED
data/lib/fat_core/hash.rb
CHANGED
@@ -10,20 +10,20 @@
|
|
10
10
|
# require 'fat_core/hash'
|
11
11
|
# ```
|
12
12
|
#
|
13
|
-
# It provides a couple of methods for manipulating the keys of a Hash:
|
14
|
-
# `#remap_keys` for translating the current set of keys to a new set provided by
|
15
|
-
# a Hash of old to new keys, and `#replace_keys` for doing a similar operation
|
16
|
-
# with an Array of new keys. Along the same line, the method `#keys_with_value`
|
17
|
-
# will return the keys in a Hash equal to the given value of any of an Array of
|
18
|
-
# values.
|
19
|
-
#
|
20
|
-
# It also provides a method for deleting all entries in a Hash whose value match
|
21
|
-
# a single value or any one of an Array of values in `#delete_with_value`
|
22
|
-
#
|
23
|
-
# Finally, it provides an `#each_pair`-like method, `#each_pair_with_flags`,
|
24
|
-
# that yields each key-value pair of the Hash along with two boolean flags that
|
25
|
-
# indicate whether the element is the first or last in the Hash.
|
26
13
|
module FatCore
|
14
|
+
# It provides a couple of methods for manipulating the keys of a Hash:
|
15
|
+
# `#remap_keys` for translating the current set of keys to a new set provided by
|
16
|
+
# a Hash of old to new keys, and `#replace_keys` for doing a similar operation
|
17
|
+
# with an Array of new keys. Along the same line, the method `#keys_with_value`
|
18
|
+
# will return the keys in a Hash equal to the given value of any of an Array of
|
19
|
+
# values.
|
20
|
+
#
|
21
|
+
# It also provides a method for deleting all entries in a Hash whose value match
|
22
|
+
# a single value or any one of an Array of values in `#delete_with_value`
|
23
|
+
#
|
24
|
+
# Finally, it provides an `#each_pair`-like method, `#each_pair_with_flags`,
|
25
|
+
# that yields each key-value pair of the Hash along with two boolean flags that
|
26
|
+
# indicate whether the element is the first or last in the Hash.
|
27
27
|
module Hash
|
28
28
|
# @group Enumerable Extensions
|
29
29
|
#
|
@@ -130,15 +130,13 @@ module FatCore
|
|
130
130
|
# @param new_keys [Array<Object>] replacement keys
|
131
131
|
# @return [Hash]
|
132
132
|
def replace_keys(new_keys)
|
133
|
-
unless keys.size == new_keys.size
|
134
|
-
raise ArgumentError, 'replace_keys: new keys size differs from key size'
|
135
|
-
end
|
133
|
+
raise ArgumentError, 'replace_keys: new keys size differs from key size' unless keys.size == new_keys.size
|
136
134
|
|
137
|
-
to_a.each_with_index.
|
135
|
+
to_a.each_with_index.to_h { |(_k, v), i| [new_keys[i], v] }
|
138
136
|
end
|
139
137
|
|
140
138
|
def <<(other)
|
141
|
-
|
139
|
+
merge(other)
|
142
140
|
end
|
143
141
|
end
|
144
142
|
end
|
data/lib/fat_core/nil.rb
CHANGED
data/lib/fat_core/range.rb
CHANGED
@@ -132,7 +132,7 @@ module FatCore
|
|
132
132
|
|
133
133
|
([min, other.min].max..[max, other.max].min)
|
134
134
|
end
|
135
|
-
|
135
|
+
alias & intersection
|
136
136
|
|
137
137
|
# Return a Range that represents the union between this range and the
|
138
138
|
# `other` range. If there is no overlap and self is not contiguous with
|
@@ -150,7 +150,7 @@ module FatCore
|
|
150
150
|
|
151
151
|
([min, other.min].min..[max, other.max].max)
|
152
152
|
end
|
153
|
-
|
153
|
+
alias + union
|
154
154
|
|
155
155
|
# The difference method, -, removes the overlapping part of the other
|
156
156
|
# argument from self. Because in the case where self is a superset of the
|
@@ -187,7 +187,7 @@ module FatCore
|
|
187
187
|
[(min..isec.min.pred), (isec.max.succ..max)]
|
188
188
|
end
|
189
189
|
end
|
190
|
-
|
190
|
+
alias - difference
|
191
191
|
|
192
192
|
# Allow erb or erubis documents to directly interpolate a Range.
|
193
193
|
#
|
@@ -297,7 +297,7 @@ module FatCore
|
|
297
297
|
# @return [Boolean] is self wholly within other
|
298
298
|
def proper_subset_of?(other)
|
299
299
|
subset_of?(other) &&
|
300
|
-
|
300
|
+
(min > other.min || max < other.max)
|
301
301
|
end
|
302
302
|
|
303
303
|
# Return whether self contains `other` range, even if their
|
@@ -324,8 +324,8 @@ module FatCore
|
|
324
324
|
# @param other [Range] range to test for overlap with self
|
325
325
|
# @return [Boolean] is there an overlap?
|
326
326
|
def overlaps?(other)
|
327
|
-
|
328
|
-
|
327
|
+
cover?(other.min) || cover?(other.max) ||
|
328
|
+
other.cover?(min) || other.cover?(max)
|
329
329
|
end
|
330
330
|
|
331
331
|
# Return whether any of the `ranges` that overlap self have overlaps among one
|
@@ -357,10 +357,10 @@ module FatCore
|
|
357
357
|
joined_range = joined_range.join(r)
|
358
358
|
break if joined_range.nil?
|
359
359
|
end
|
360
|
-
if
|
361
|
-
joined_range.min <= min && joined_range.max >= max
|
362
|
-
else
|
360
|
+
if joined_range.nil?
|
363
361
|
false
|
362
|
+
else
|
363
|
+
joined_range.min <= min && joined_range.max >= max
|
364
364
|
end
|
365
365
|
end
|
366
366
|
|
data/lib/fat_core/string.rb
CHANGED
@@ -58,7 +58,7 @@ module FatCore
|
|
58
58
|
line_width_so_far = 0
|
59
59
|
words = split(' ')
|
60
60
|
words.each do |w|
|
61
|
-
w = ::String.new(' ') * hang + w if !first_line && first_word_on_line
|
61
|
+
w = (::String.new(' ') * hang) + w if !first_line && first_word_on_line
|
62
62
|
w = ::String.new(' ') + w unless first_word_on_line
|
63
63
|
result << w
|
64
64
|
first_word_on_line = false
|
@@ -85,13 +85,13 @@ module FatCore
|
|
85
85
|
r = dup
|
86
86
|
r = r.gsub(/[{]/, 'XzXzXobXzXzX')
|
87
87
|
r = r.gsub(/[}]/, 'XzXzXcbXzXzX')
|
88
|
-
r = r.gsub(
|
89
|
-
r = r.gsub(
|
90
|
-
r = r.gsub(
|
91
|
-
r = r.gsub(
|
92
|
-
r = r.gsub(
|
93
|
-
r = r.gsub(
|
94
|
-
r = r.gsub(/([_$&%#])/) { |m|
|
88
|
+
r = r.gsub("\\", '\textbackslash{}')
|
89
|
+
r = r.gsub("^", '\textasciicircum{}')
|
90
|
+
r = r.gsub("~", '\textasciitilde{}')
|
91
|
+
r = r.gsub("|", '\textbar{}')
|
92
|
+
r = r.gsub("<", '\textless{}')
|
93
|
+
r = r.gsub(">", '\textgreater{}')
|
94
|
+
r = r.gsub(/([_$&%#])/) { |m| "\\#{m}" }
|
95
95
|
r = r.gsub('XzXzXobXzXzX', '\\{')
|
96
96
|
r.gsub('XzXzXcbXzXzX', '\\}')
|
97
97
|
end
|
data/lib/fat_core/symbol.rb
CHANGED
@@ -14,9 +14,9 @@ module FatCore
|
|
14
14
|
#
|
15
15
|
# @return [String]
|
16
16
|
def as_string
|
17
|
-
to_s.tr('_', ' ').split
|
17
|
+
to_s.tr('_', ' ').split.join(' ').entitle
|
18
18
|
end
|
19
|
-
|
19
|
+
alias entitle as_string
|
20
20
|
|
21
21
|
# Return self. This (together with String#as_sym) allows `#as_sym` to be
|
22
22
|
# applied to a string or Symbol and get back a Symbol with out testing for
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/array_spec.rb
CHANGED
@@ -8,19 +8,61 @@ describe Array do
|
|
8
8
|
expect(letters.last_i).to eq(25)
|
9
9
|
end
|
10
10
|
|
11
|
-
it '
|
12
|
-
expect(%w
|
13
|
-
expect(%w
|
14
|
-
expect(%w
|
15
|
-
expect(%w
|
16
|
-
expect(%w
|
17
|
-
end
|
18
|
-
|
19
|
-
it '
|
20
|
-
|
21
|
-
expect(%w
|
22
|
-
expect(%w
|
23
|
-
expect(%w
|
24
|
-
expect(%w
|
11
|
+
it 'intersect_with_dups' do
|
12
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[A B A])).to eq(%w[A A B A A B])
|
13
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[A B])).to eq(%w[A A B A A B])
|
14
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[A])).to eq(%w[A A A A])
|
15
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[B])).to eq(%w[B B])
|
16
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[C])).to eq(%w[C])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'intersect_with_dups multiple' do
|
20
|
+
# Include only elements that occur in /all/ other arrays.
|
21
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[A B A], %w[A D F])).to eq(%w[A A A A])
|
22
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[A B A], %w[B D F])).to eq(%w[B B])
|
23
|
+
expect(%w[A A B A C A B].intersect_with_dups(%w[A D E F], %w[B D F])).to eq(%w[])
|
24
|
+
# expect(%w[A A B A C A B].intersect_with_dups(%w[A B])).to eq(%w[A A B A A B])
|
25
|
+
# expect(%w[A A B A C A B].intersect_with_dups(%w[A])).to eq(%w[A A A A])
|
26
|
+
# expect(%w[A A B A C A B].intersect_with_dups(%w[B])).to eq(%w[B B])
|
27
|
+
# expect(%w[A A B A C A B].intersect_with_dups(%w[C])).to eq(%w[C])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'diff_with_dups' do
|
31
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[A B A])).to eq(%w[C])
|
32
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[A B])).to eq(%w[C])
|
33
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[A])).to eq(%w[B C B])
|
34
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[B])).to eq(%w[A A A C A])
|
35
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[C])).to eq(%w[A A B A A B])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'diff_with_dups multiple' do
|
39
|
+
# Include only elements that occur in /none/ of the other arrays.
|
40
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[A C], %w[D F])).to eq(%w[B B])
|
41
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[A C], %w[D F], %w[B R T])).to eq(%w[])
|
42
|
+
expect(%w[A A B A C A B].diff_with_dups(%w[R B])).to eq(%w[A A A C A])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'comma_join' do
|
46
|
+
expect(%w[].comma_join).to eq('')
|
47
|
+
expect(%w[A].comma_join).to eq('A')
|
48
|
+
expect(%w[A B].comma_join).to eq('A and B')
|
49
|
+
expect(%w[A B C].comma_join).to eq('A, B, and C')
|
50
|
+
expect([1, 1, 2, 3, 5, 8].comma_join).to eq('1, 1, 2, 3, 5, and 8')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'comma_join with only sep param' do
|
54
|
+
expect(%w[].comma_join(sep: '-')).to eq('')
|
55
|
+
expect(%w[A].comma_join(sep: '-')).to eq('A')
|
56
|
+
expect(%w[A B].comma_join(sep: '-')).to eq('A-B')
|
57
|
+
expect(%w[A B C].comma_join(sep: '-')).to eq('A-B-C')
|
58
|
+
expect([1, 1, 2, 3, 5, 8].comma_join(sep: '-')).to eq('1-1-2-3-5-8')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'comma_join with only last_sep param' do
|
62
|
+
expect(%w[].comma_join(last_sep: '*')).to eq('')
|
63
|
+
expect(%w[A].comma_join(last_sep: '*')).to eq('A')
|
64
|
+
expect(%w[A B].comma_join(last_sep: '*')).to eq('A*B')
|
65
|
+
expect(%w[A B C].comma_join(last_sep: '*')).to eq('A, B*C')
|
66
|
+
expect([1, 1, 2, 3, 5, 8].comma_join(last_sep: '*')).to eq('1, 1, 2, 3, 5*8')
|
25
67
|
end
|
26
68
|
end
|
data/spec/lib/date_spec.rb
CHANGED
@@ -461,7 +461,7 @@ describe Date do
|
|
461
461
|
it 'prints itself in org form' do
|
462
462
|
expect(described_class.today.org).to eq('[2012-07-18 Wed]')
|
463
463
|
expect((described_class.today + 1.day).org).to eq('[2012-07-19 Thu]')
|
464
|
-
expect((described_class.today + 1.day).org(true)).to eq('<2012-07-19 Thu>')
|
464
|
+
expect((described_class.today + 1.day).org(active: true)).to eq('<2012-07-19 Thu>')
|
465
465
|
end
|
466
466
|
|
467
467
|
it 'prints itself in eng form' 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
|
+
version: 5.0.1
|
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: 2024-08-
|
11
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -177,6 +177,7 @@ executables:
|
|
177
177
|
extensions: []
|
178
178
|
extra_rdoc_files: []
|
179
179
|
files:
|
180
|
+
- ".envrc"
|
180
181
|
- ".gitignore"
|
181
182
|
- ".rspec"
|
182
183
|
- ".rubocop.yml"
|