refinements 9.4.0 → 9.5.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: 48645ddfcd7e2ab3a7930401d2161dd259de6bf89ac2f5dbdf8f32015a9c9ed2
4
- data.tar.gz: 8788e3eef62a5856f9136b38b6b76fe9d4c5a8db56b39394f8021bb6ea1db36d
3
+ metadata.gz: 06c161de8cf1a100c8df6267ef2116368743557dac4504e9617b19dd063520aa
4
+ data.tar.gz: 60389a48bc41a581d835ac67c80e71a8db438ddbccf070336e1128d4d430e87a
5
5
  SHA512:
6
- metadata.gz: 51c14c8e25b187ae86630f6c8c017cae3f53f16a4a1a72a9cbdfd3d5e2e83fe1e1bb07b2eacfb4865e35c5bd32092021f4758fdc454be900f42477a8f1a5f190
7
- data.tar.gz: 8b4a378f5bd2e1eec9a3ca9c1bf72c0a5e3773dbe3ece7bebf5ac4bf3be815bd35b25ddc918de5a51116e6d43c98d4b0e54b423beaa2e1532a48645f477337b5
6
+ metadata.gz: 95c680f9fe5df9820d72462e40984eafe398b0cf81589b6525026978a477950723608d8d39b89b3fe0c61e888ce3a2a166d2e54ec26676a3c9621f6b712e3828
7
+ data.tar.gz: b3743029174a74733328346ce1264d9f7dab9876222deb4a3b3f96a38817cf8b7c0b35eabc62639b5f7e7f4f2e1572282d1f31952e6c55b90d6f65df2b190bef
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -254,6 +254,21 @@ example.ring { |(before, current, after)| puts "#{before} #{current} #{after}" }
254
254
  # [2 3 1]
255
255
  ----
256
256
 
257
+ ===== #to_sentence
258
+
259
+ Answers a sentence using `", "` as the default delimiter and `"and"` as the default conjunction.
260
+ Useful when building documentation, answering human readable error messages, etc.
261
+
262
+ [source,ruby]
263
+ ----
264
+ [].to_sentence # ""
265
+ ["test"].to_sentence # "test"
266
+ ["a", :b].to_sentence # "a and b"
267
+ [1, "a", :b, 2.0, /\w+/].map(&:inspect).to_sentence # 1, "a", :b, 2.0, and /\w+/
268
+ %w[one two three].to_sentence # "one, two, and three"
269
+ %w[eins zwei drei].to_sentence delimiter: " ", conjunction: "und" # "eins zwei und drei"
270
+ ----
271
+
257
272
  ==== Big Decimal
258
273
 
259
274
  ===== #inspect
@@ -32,6 +32,14 @@ module Refinements
32
32
  def pad(value, max: size) = dup.fill(value, size..(max - 1))
33
33
 
34
34
  def ring(&) = [last, *self, first].each_cons(3, &)
35
+
36
+ def to_sentence delimiter: ", ", conjunction: "and"
37
+ case length
38
+ when (3..) then "#{self[..-2].join delimiter}#{delimiter}#{conjunction} #{last}"
39
+ when 2 then join " #{conjunction} "
40
+ else join
41
+ end
42
+ end
35
43
  end
36
44
  end
37
45
  end
@@ -21,7 +21,8 @@ module Refinements
21
21
  def compress!
22
22
  return self if empty?
23
23
 
24
- compact!.delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
24
+ compact!
25
+ delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
25
26
  end
26
27
 
27
28
  def deep_merge other
data/refinements.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "refinements"
5
- spec.version = "9.4.0"
5
+ spec.version = "9.5.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/refinements"
data.tar.gz.sig CHANGED
Binary file
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: 9.4.0
4
+ version: 9.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
29
29
  RFE=
30
30
  -----END CERTIFICATE-----
31
- date: 2022-05-07 00:00:00.000000000 Z
31
+ date: 2022-06-25 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.3.13
83
+ rubygems_version: 3.3.16
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: A collection of refinements to core Ruby objects.
metadata.gz.sig CHANGED
Binary file