refinements 8.2.2 → 8.3.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: f1300ddb397a467ad30d958def06e67d67bb7ef290534c72efb4b2c573b6a12c
4
- data.tar.gz: 67dd6116fe43e6853ef72ea0d3a61006ebb0fd6a432cc8d6ce0ba848f85f0e1b
3
+ metadata.gz: d389fcb07d681440a24f0b368c81a76948e15b71287a850e857f8e018fc973da
4
+ data.tar.gz: 3f7a815dbc49376aad77ab549e77bf9e607bec74ff136b537dfccc371649fe4a
5
5
  SHA512:
6
- metadata.gz: f050fefc0826e2270ee906f494141f6ab057b849af7f2cb1eb0c60efe86e385d2189e508b4706dd3f779067d96212e066172dba0b1ae25752cf3a404028e1bd7
7
- data.tar.gz: 11baf97860fe19ea8901a550dffe7e3d7d764f9c1add07ce6e0677bb3a17bee4ec4832dde316d1108d91ea1acf53566d33995982231cba8d0a99d23b844636da
6
+ metadata.gz: d7269907e701c6917bb5c096af4bbf1650d03b8ffb752b56c37baa895e8eff649359246b79e0a19b3b790d6dde60711a06aeb0a37b3da0c080a64bbcc54e96bf
7
+ data.tar.gz: 5cbd5fd8f553c47fa5f77e4145c48af1ac3467927fb09aae8db48639a92c6000c255b75d66d90824474c7dbffd10ef19ee5581e3d5da83f4bb0526d0d8d1a2e1
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -288,6 +288,30 @@ example = Hash.with_default []
288
288
  example[:b] # => []
289
289
  ----
290
290
 
291
+ ===== #compress
292
+
293
+ Removes empty objects without mutating itself.
294
+
295
+ [source,ruby]
296
+ ----
297
+ object = Object.new
298
+ example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
299
+ example.compress # => {a: 1, b: "blueberry", g: object}
300
+ example # => {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
301
+ ----
302
+
303
+ ===== #compress!
304
+
305
+ Removes empty objects while mutating itself.
306
+
307
+ [source,ruby]
308
+ ----
309
+ object = Object.new
310
+ example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
311
+ example.compress! # => {a: 1, b: "blueberry", g: object}
312
+ example # => {a: 1, b: "blueberry", g: object}
313
+ ----
314
+
291
315
  ===== #deep_merge
292
316
 
293
317
  Merges deeply nested hashes together without mutating itself.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Refinements
4
+ # Provides additional enhancements to the Array primitive.
4
5
  module Arrays
5
6
  refine Array do
6
7
  def compress = compact.reject(&:empty?)
@@ -3,6 +3,7 @@
3
3
  require "bigdecimal"
4
4
 
5
5
  module Refinements
6
+ # Provides additional enhancements to the BigDecimal primitive.
6
7
  module BigDecimals
7
8
  refine BigDecimal do
8
9
  def inspect = format("#<BigDecimal:%{id} %{string}>", id: object_id, string: to_s("F"))
@@ -3,6 +3,7 @@
3
3
  require "date"
4
4
 
5
5
  module Refinements
6
+ # Provides additional enhancements to the DateTime primitive.
6
7
  module DateTimes
7
8
  refine DateTime.singleton_class do
8
9
  def utc = now.new_offset(0)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Refinements
4
+ # Provides additional enhancements to the Hash primitive.
4
5
  module Hashes
5
6
  refine Hash.singleton_class do
6
7
  def infinite
@@ -11,6 +12,12 @@ module Refinements
11
12
  end
12
13
 
13
14
  refine Hash do
15
+ def compress = dup.compress!
16
+
17
+ def compress!
18
+ compact!.delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
19
+ end
20
+
14
21
  def deep_merge other
15
22
  clazz = self.class
16
23
 
@@ -62,13 +69,13 @@ module Refinements
62
69
  end
63
70
  end
64
71
 
65
- def stringify_keys = reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
72
+ def stringify_keys = transform_keys(&:to_s)
66
73
 
67
- def stringify_keys! = replace(stringify_keys)
74
+ def stringify_keys! = transform_keys!(&:to_s)
68
75
 
69
- def symbolize_keys = reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
76
+ def symbolize_keys = transform_keys(&:to_sym)
70
77
 
71
- def symbolize_keys! = replace(symbolize_keys)
78
+ def symbolize_keys! = transform_keys!(&:to_sym)
72
79
 
73
80
  def use &block
74
81
  return [] unless block
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "8.2.2"
8
+ VERSION = "8.3.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
10
10
  end
11
11
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Refinements
4
+ # Provides additional enhancements to the IO primitive.
4
5
  module IOs
5
6
  refine IO.singleton_class do
6
7
  def void
@@ -3,9 +3,9 @@
3
3
  require "pathname"
4
4
 
5
5
  module Refinements
6
+ # Provides additional enhancements to the Pathname primitive.
6
7
  module Pathnames
7
8
  refine Kernel do
8
- # :reek:UncommunicativeMethodName
9
9
  def Pathname object
10
10
  return super(String(object)) unless object
11
11
 
@@ -3,6 +3,7 @@
3
3
  require "stringio"
4
4
 
5
5
  module Refinements
6
+ # Provides additional enhancements to the StringIO primitive.
6
7
  module StringIOs
7
8
  refine StringIO do
8
9
  def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Refinements
4
+ # Provides additional enhancements to the String primitive.
4
5
  module Strings
5
6
  DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
6
7
 
7
8
  refine String do
8
- def blank? = match?(/\A\s*\z/)
9
+ def blank? = empty? || match?(/\A[[:space:]]*\z/)
9
10
 
10
11
  def camelcase
11
12
  return up unless match? DELIMITERS
@@ -35,7 +36,7 @@ module Refinements
35
36
  def indent multiplier = 1, padding: " "
36
37
  return self if multiplier.negative?
37
38
 
38
- padding * multiplier + self
39
+ (padding * multiplier) + self
39
40
  end
40
41
 
41
42
  def last number = 0
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Refinements
4
+ # Provides additional enhancements to the Struct primitive.
4
5
  module Structs
5
6
  refine Struct.singleton_class do
6
7
  def keyworded? = inspect.include?("keyword_init: true")
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: 8.2.2
4
+ version: 8.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
29
  W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2021-09-06 00:00:00.000000000 Z
31
+ date: 2021-09-26 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.2.27
78
+ rubygems_version: 3.2.28
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: A collection of refinements to core Ruby objects.
metadata.gz.sig CHANGED
Binary file