refinements 14.1.0 → 14.2.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
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +38 -7
- data/lib/refinements/date_time.rb +4 -1
- data/lib/refinements/pathname.rb +1 -1
- data/lib/refinements/string.rb +28 -6
- data/lib/refinements/time.rb +10 -0
- data/lib/refinements.rb +1 -0
- data/refinements.gemspec +1 -1
- data.tar.gz.sig +2 -5
- metadata +2 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d020697c0869daf2e3bcc99d87db35971ed15bd9a232b930f5420fdd1e463822
|
|
4
|
+
data.tar.gz: 1a90b8c69ca796cb3445939e9661d6f41f89eb54f52142f98d868783d067402c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b855ed89c0deadec703182707a3a77f025ac02dd9893e81bacc1bb63f85dcf9e7c3ca63cdabd448417af4e4be1b92920271129ed3e575afc9210acc73cc8f01c
|
|
7
|
+
data.tar.gz: 7f3933aef0ab201659aa807360f84c9dacc7844e2b86800e49cebf20f62dcb3fab20e1357468df90b4b2c5e931c064f0373743097206fd180f62cdaf2214cfdd
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/README.adoc
CHANGED
|
@@ -25,6 +25,7 @@ Enhances the following objects:
|
|
|
25
25
|
* StringIO
|
|
26
26
|
* Struct
|
|
27
27
|
* Symbol
|
|
28
|
+
* Time
|
|
28
29
|
|
|
29
30
|
== Requirements
|
|
30
31
|
|
|
@@ -91,6 +92,7 @@ require "refinements/string"
|
|
|
91
92
|
require "refinements/string_io"
|
|
92
93
|
require "refinements/struct"
|
|
93
94
|
require "refinements/symbol"
|
|
95
|
+
require "refinements/time"
|
|
94
96
|
----
|
|
95
97
|
|
|
96
98
|
=== Using
|
|
@@ -114,6 +116,7 @@ class Example
|
|
|
114
116
|
using Refinements::StringIO
|
|
115
117
|
using Refinements::Struct
|
|
116
118
|
using Refinements::Symbol
|
|
119
|
+
using Refinements::Time
|
|
117
120
|
end
|
|
118
121
|
----
|
|
119
122
|
|
|
@@ -462,6 +465,8 @@ Any object that _is not_ the same type will have a `nil` value as shown in the l
|
|
|
462
465
|
|
|
463
466
|
Answers new DateTime object for current UTC date/time.
|
|
464
467
|
|
|
468
|
+
⚠️ This method (and refinement) is deprecated and will be removed in the next major release.
|
|
469
|
+
|
|
465
470
|
[source,ruby]
|
|
466
471
|
----
|
|
467
472
|
DateTime.utc # "#<DateTime: 2019-12-31T18:17:00+00:00 ((2458849j,65820s,181867000n),+0s,2299161j)>"
|
|
@@ -1446,21 +1451,20 @@ Answers a title string with proper capitalization of each word.
|
|
|
1446
1451
|
|
|
1447
1452
|
===== #trim_end
|
|
1448
1453
|
|
|
1449
|
-
Answers the trimmed end of a string
|
|
1454
|
+
Answers the trimmed end of a string for maximum length with optional delimiter and/or overflow.
|
|
1450
1455
|
|
|
1451
|
-
The delimiter is the second positional parameter (optional) and is `nil` by default. A
|
|
1456
|
+
The delimiter is the second positional parameter (optional) and is `nil` by default. A string or regular expression can be used to customize behavior.
|
|
1452
1457
|
|
|
1453
|
-
The trailer is an optional keyword parameter that is an ellipsis
|
|
1458
|
+
The trailer is an optional keyword parameter that is an ellipsis by default. The trailer can be a custom or empty string. The string size of the trailer is added to the size of the string being trimmed, so keep this in mind when setting the maximum length.
|
|
1454
1459
|
|
|
1455
1460
|
[source,ruby]
|
|
1456
1461
|
----
|
|
1457
1462
|
demo = "It was the best of times"
|
|
1458
|
-
|
|
1463
|
+
size = demo.size
|
|
1459
1464
|
|
|
1460
1465
|
demo.trim_end 9 # "It was..."
|
|
1461
1466
|
demo.trim_end 12 # "It was th..."
|
|
1462
|
-
demo.trim_end
|
|
1463
|
-
demo.trim_end Float::INFINITY # "It was the best of times"
|
|
1467
|
+
demo.trim_end size # "It was the best of times"
|
|
1464
1468
|
demo.trim_end 12, " " # "It was..."
|
|
1465
1469
|
demo.trim_end 12, /\s/ # "It was..."
|
|
1466
1470
|
demo.trim_end 6, trailer: "" # "It was"
|
|
@@ -1468,6 +1472,22 @@ demo.trim_end 16, trailer: "... (more)" # "It was... (more)"
|
|
|
1468
1472
|
"demo".trim_end 3 # "..."
|
|
1469
1473
|
----
|
|
1470
1474
|
|
|
1475
|
+
===== #trim_middle
|
|
1476
|
+
|
|
1477
|
+
Answers the trimmed middle of a string for maximum length with optional gap (default: ellipsis). The minimum length is always the size of the gap plus one character on each side of the gap.
|
|
1478
|
+
|
|
1479
|
+
[source,ruby]
|
|
1480
|
+
----
|
|
1481
|
+
demo = "It was the best of times"
|
|
1482
|
+
size = demo.size
|
|
1483
|
+
|
|
1484
|
+
demo.trim_middle 14 # "It w...times"
|
|
1485
|
+
demo.trim_middle size # "It was the...t of times"
|
|
1486
|
+
"space".trim_middle 5 # "s...e"
|
|
1487
|
+
demo.trim_middle 14, gap: "+" # "It was+ times"
|
|
1488
|
+
demo.trim_middle 3 # "It was the best of times"
|
|
1489
|
+
----
|
|
1490
|
+
|
|
1471
1491
|
===== #truthy?
|
|
1472
1492
|
|
|
1473
1493
|
Answers if string is truthy.
|
|
@@ -1633,7 +1653,6 @@ Enhances symbol-to-proc functionality by allowing you to send positional, keywor
|
|
|
1633
1653
|
|
|
1634
1654
|
[source,ruby]
|
|
1635
1655
|
----
|
|
1636
|
-
|
|
1637
1656
|
%w[clue crow cow].map(&:tr.call("c", "b")) # ["blue", "brow", "bow"]
|
|
1638
1657
|
[1.3, 1.5, 1.9].map(&:round.call(half: :up)) # [1, 2, 2]
|
|
1639
1658
|
[%w[a b c], %w[c a b]].map(&:index.call { |element| element == "b" }) # [1, 2]
|
|
@@ -1643,6 +1662,18 @@ Enhances symbol-to-proc functionality by allowing you to send positional, keywor
|
|
|
1643
1662
|
|
|
1644
1663
|
⚠️ Use of `#call` without any arguments should be avoided in order to not incur extra processing costs since the original symbol-to-proc call can be used instead.
|
|
1645
1664
|
|
|
1665
|
+
==== Time
|
|
1666
|
+
|
|
1667
|
+
===== #rfc_3339
|
|
1668
|
+
|
|
1669
|
+
Answers time, as a string, in RFC 3339 format.
|
|
1670
|
+
|
|
1671
|
+
[source,ruby]
|
|
1672
|
+
----
|
|
1673
|
+
Time.now.rfc_3339 # "2026-01-24T08:56:55-07:00"
|
|
1674
|
+
Time.now.utc.rfc_3339 # "2026-01-24T15:57:13+00:00"
|
|
1675
|
+
----
|
|
1676
|
+
|
|
1646
1677
|
== Development
|
|
1647
1678
|
|
|
1648
1679
|
To contribute, run:
|
|
@@ -6,7 +6,10 @@ module Refinements
|
|
|
6
6
|
# Provides additional enhancements to the DateTime primitive.
|
|
7
7
|
module DateTime
|
|
8
8
|
refine ::DateTime.singleton_class do
|
|
9
|
-
def utc
|
|
9
|
+
def utc
|
|
10
|
+
warn "`DateTime.#{__method__}` is deprecated, use `Time` instead.", category: :deprecated
|
|
11
|
+
now.new_offset 0
|
|
12
|
+
end
|
|
10
13
|
end
|
|
11
14
|
end
|
|
12
15
|
end
|
data/lib/refinements/pathname.rb
CHANGED
data/lib/refinements/string.rb
CHANGED
|
@@ -52,7 +52,15 @@ module Refinements
|
|
|
52
52
|
.then { |parts| combine parts, :down, "_" }
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
def squish
|
|
55
|
+
def squish
|
|
56
|
+
duplicate = dup
|
|
57
|
+
|
|
58
|
+
# Find two or more spaces/tabs/newlines or a single space that isn't " ".
|
|
59
|
+
duplicate.gsub!(/([[:space:]]{2,}|[[[:space:]]&&[^ ]])/, " ")
|
|
60
|
+
|
|
61
|
+
duplicate.strip!
|
|
62
|
+
duplicate
|
|
63
|
+
end
|
|
56
64
|
|
|
57
65
|
def titleize
|
|
58
66
|
return capitalize unless match? DELIMITERS
|
|
@@ -62,12 +70,26 @@ module Refinements
|
|
|
62
70
|
.then { |parts| combine parts, :up, "/" }
|
|
63
71
|
end
|
|
64
72
|
|
|
65
|
-
def trim_end
|
|
66
|
-
return dup if
|
|
73
|
+
def trim_end maximum, delimiter = nil, trailer: "..."
|
|
74
|
+
return dup if size <= maximum
|
|
75
|
+
|
|
76
|
+
offset = maximum - trailer.size
|
|
77
|
+
stop = delimiter ? rindex(delimiter, offset) || offset : offset
|
|
78
|
+
"#{self[...stop]}#{trailer}"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def trim_middle maximum, gap: "..."
|
|
82
|
+
gap_size = gap.size
|
|
83
|
+
minimum = gap_size + 2
|
|
84
|
+
limit = maximum - gap_size
|
|
85
|
+
|
|
86
|
+
return dup if maximum < minimum || maximum > size
|
|
87
|
+
return "#{first}#{gap}#{last}" if minimum == maximum
|
|
88
|
+
|
|
89
|
+
half = limit / 2
|
|
90
|
+
stop = half.odd? ? half - 1 : half
|
|
67
91
|
|
|
68
|
-
|
|
69
|
-
maximum = delimiter ? rindex(delimiter, offset) || offset : offset
|
|
70
|
-
"#{self[...maximum]}#{trailer}"
|
|
92
|
+
"#{self[...stop]}#{gap}#{self[-half...]}"
|
|
71
93
|
end
|
|
72
94
|
|
|
73
95
|
def truthy? = %w[true yes on t y 1].include? downcase.strip
|
data/lib/refinements.rb
CHANGED
data/refinements.gemspec
CHANGED
data.tar.gz.sig
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
w�p_4��̳��βg_�F8��~
|
|
4
|
-
l�R�>C�wI،7 韌��柀x������<2�X��f:��~~d����D���~m8���#������WG��r?8�,7�! ��cO :��b&4���������)S����
|
|
5
|
-
�8����yFLY!z��Zy9��{��6-�b}���������H�3��V��1cnr7~@S��Sy!
|
|
1
|
+
A7g�"��^0��:~3Ef���7%��8�ڲ^�V��mB6�`K�{#*{��5"��tG���\�*��g��%���@w��$�!<~
|
|
2
|
+
�W(��`�q�֊@�W��3l�;2��0��\���V�hW_wOˡ-����p�����C�b,f��;$�ߏ"$w�[���Ц.k�Fg��'�R/ߤ�����a�>�8H�/������=��l<��'�E���U�N�W=�1_P�
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: refinements
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 14.
|
|
4
|
+
version: 14.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brooke Kuhlmann
|
|
@@ -62,6 +62,7 @@ files:
|
|
|
62
62
|
- lib/refinements/string_io.rb
|
|
63
63
|
- lib/refinements/struct.rb
|
|
64
64
|
- lib/refinements/symbol.rb
|
|
65
|
+
- lib/refinements/time.rb
|
|
65
66
|
- refinements.gemspec
|
|
66
67
|
homepage: https://alchemists.io/projects/refinements
|
|
67
68
|
licenses:
|
metadata.gz.sig
CHANGED
|
Binary file
|