refinements 8.1.0 → 8.2.2

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: 6446344f206e8c2b4175dedc5ccd4d14c4bcaadd6d7969fcf04ef3d185143b03
4
- data.tar.gz: ccdd0a5a93d36e1c4f4e5ed23b2f29ee3ee1cd3d8654a919ade1ed17841228cf
3
+ metadata.gz: f1300ddb397a467ad30d958def06e67d67bb7ef290534c72efb4b2c573b6a12c
4
+ data.tar.gz: 67dd6116fe43e6853ef72ea0d3a61006ebb0fd6a432cc8d6ce0ba848f85f0e1b
5
5
  SHA512:
6
- metadata.gz: 4b27775e5e325f98b308bdfd913129074266f75c4601caec7d48e9ca64e7608d24a2ebcbea4795a7548d61db36fecfe8ddbab3593c9aa9df8ca153b63ad41dac
7
- data.tar.gz: afe11cd5ac6e81723f4afef741699a7615e96103c85fef24f51749e35ac02c79ffb0c9eb0fc459d63b7bba26f0b3469d251ae562b211fae4b8b29dbac71f02dc
6
+ metadata.gz: f050fefc0826e2270ee906f494141f6ab057b849af7f2cb1eb0c60efe86e385d2189e508b4706dd3f779067d96212e066172dba0b1ae25752cf3a404028e1bd7
7
+ data.tar.gz: 11baf97860fe19ea8901a550dffe7e3d7d764f9c1add07ce6e0677bb3a17bee4ec4832dde316d1108d91ea1acf53566d33995982231cba8d0a99d23b844636da
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -11,7 +11,9 @@ image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchem
11
11
  [link=https://circleci.com/gh/bkuhlmann/refinements]
12
12
  image::https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg[Circle CI Status]
13
13
 
14
- A collection of refinements (enhancements) to primitive Ruby objects.
14
+ Refinements is a collection of enhancements to primitive Ruby objects without needing to resort
15
+ painful and hard to debug monkey patches. These refinements give you additional syntactic sugar to
16
+ build clean and concise implementations all while using less code.
15
17
 
16
18
  toc::[]
17
19
 
@@ -135,6 +137,23 @@ Removes given array or elements without mutating itself.
135
137
  [1, 2, 3, 4, 5].excluding 4, 5 # => [1, 2, 3]
136
138
  ----
137
139
 
140
+ ===== #filter_find
141
+
142
+ Answers the first truthy and filtered result from a collection.
143
+
144
+ [source,ruby]
145
+ ----
146
+ handlers = [
147
+ ->(object) { object if object == :b },
148
+ proc { false },
149
+ ->(object) { object if object == :a }
150
+ ]
151
+
152
+ handlers.filter_find # => Enumerator::Lazy
153
+ handlers.filter_find { |handler| handler.call :a } # => :a
154
+ handlers.filter_find { |handler| handler.call :x } # => nil
155
+ ----
156
+
138
157
  ===== #including
139
158
 
140
159
  Adds given array or elements without mutating itself.
@@ -156,6 +175,19 @@ Inserts additional elements or array between all members of given array.
156
175
  [1, 2, 3].intersperse %i[a b c] # => [1, :a, :b, :c, 2, :a, :b, :c, 3]
157
176
  ----
158
177
 
178
+ ===== #maximum
179
+
180
+ Answers the maximum extracted value from a collection of objects.
181
+
182
+ [source,ruby]
183
+ ----
184
+ Point = Struct.new :x, :y, keyword_init: true
185
+ points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
186
+
187
+ points.maximum(:x) # => 2
188
+ points.maximum(:y) # => 3
189
+ ----
190
+
159
191
  ===== #mean
160
192
 
161
193
  Answers mean/average all elements within an array.
@@ -168,6 +200,19 @@ Answers mean/average all elements within an array.
168
200
  [1.25, 1.5, 1.75].mean # => 1.5
169
201
  ----
170
202
 
203
+ ===== #minimum
204
+
205
+ Answers the minimum extracted value from a collection of objects.
206
+
207
+ [source,ruby]
208
+ ----
209
+ Point = Struct.new :x, :y, keyword_init: true
210
+ points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
211
+
212
+ points.minimum(:x) # => 0
213
+ points.minimum(:y) # => 1
214
+ ----
215
+
171
216
  ===== #pad
172
217
 
173
218
  Answers new array padded with given value up to a maximum size. Useful in situations where an array
@@ -492,7 +537,7 @@ Wraps `Dir.mktmpdir` with the following behavior (see
492
537
  link:https://rubyapi.org/o/Dir.mktmpdir#method-c-mktmpdir[Dir.mktmpdir] for details):
493
538
 
494
539
  * *Without Block* - Answers a newly created Pathname instance which is not automatically cleaned up.
495
- * *With Block* Yields a Pathname instance, answers result of given block, and automatidally cleans
540
+ * *With Block* Yields a Pathname instance, answers result of given block, and automatically cleans
496
541
  up temporary directory after block exits.
497
542
 
498
543
  The following examples use truncated temporary directories for illustration purposes only. In
@@ -9,11 +9,17 @@ module Refinements
9
9
 
10
10
  def excluding(*elements) = self - elements.flatten
11
11
 
12
+ def filter_find(&block) = block ? lazy.map(&block).find(&:itself) : lazy
13
+
12
14
  def including(*elements) = self + elements.flatten
13
15
 
14
16
  def intersperse(*elements) = product([elements]).tap(&:pop).flatten.push(last)
15
17
 
16
- def mean = size.zero? ? 0 : sum(0) / size
18
+ def maximum(key) = map(&key).max
19
+
20
+ def mean = size.zero? ? 0 : sum(0.0) / size
21
+
22
+ def minimum(key) = map(&key).min
17
23
 
18
24
  def pad(value, max: size) = dup.fill(value, size..(max - 1))
19
25
 
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "8.1.0"
9
- VERSION_LABEL = "#{LABEL} #{VERSION}"
8
+ VERSION = "8.2.2"
9
+ VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
10
10
  end
11
11
  end
@@ -7,7 +7,7 @@ module Refinements
7
7
 
8
8
  def with_keywords(**arguments) = keyworded? ? new(**arguments) : new.merge!(**arguments)
9
9
 
10
- def with_positions(*values) = keyworded? ? new(**Hash[members.zip values]) : new(*values)
10
+ def with_positions(*values) = keyworded? ? new(**members.zip(values).to_h) : new(*values)
11
11
  end
12
12
 
13
13
  refine Struct do
@@ -21,9 +21,7 @@ module Refinements
21
21
  def revalue attributes = each_pair
22
22
  return self unless block_given?
23
23
 
24
- dup.tap do |copy|
25
- attributes.each { |key, value| copy[key] = yield self[key], value }
26
- end
24
+ dup.tap { |copy| attributes.each { |key, value| copy[key] = yield self[key], value } }
27
25
  end
28
26
 
29
27
  def revalue! attributes = each_pair
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.1.0
4
+ version: 8.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIC/jCCAeagAwIBAgIBAzANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
14
- a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMDAzMTUxNDQ1MzJaFw0yMTAzMTUx
15
- NDQ1MzJaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
13
+ MIIC/jCCAeagAwIBAgIBBDANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
14
+ a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMTAzMTkxMjQ4MDZaFw0yMjAzMTkx
15
+ MjQ4MDZaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
16
16
  IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6l1qpXTiomH1RfMRloyw7MiE
17
17
  xyVx/x8Yc3EupdH7uhNaTXQGyORN6aOY//1QXXMHIZ9tW74nZLhesWMSUMYy0XhB
18
18
  brs+KkurHnc9FnEJAbG7ebGvl/ncqZt72nQvaxpDxvuCBHgJAz+8i5wl6FhLw+oT
@@ -20,15 +20,15 @@ cert_chain:
20
20
  D5vkU0YlAm1r98BymuJlcQ1qdkVEI1d48ph4kcS0S0nv1RiuyVb6TCAR3Nu3VaVq
21
21
  3fPzZKJLZBx67UvXdbdicWPiUR75elI4PXpLIic3xytaF52ZJYyKZCNZJhNwfQID
22
22
  AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0nzow9vc
23
- 2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAIHhAlD3po4sTYqacXaQ
24
- XI9jIhrfMy//2PgbHWcETtlJPBeNUbbSNBABcllUHKqYsVDlSvSmss034KSWNR8F
25
- bF1GcloicyvcCC4y6IoW4it0COAcdeaaxkxiBSgKdQFpff9REnDlIKK4uQ9lLxIo
26
- Y2G5xubiziKZkyfWFuSr67PIjW3Bu673D1JVBArhA1qbgQmYQcy1CkGOjo+iO8Nf
27
- 7u/QSfBHb+r/bXhKscDgPpnKwbUmvgO2+94zJG9KsrmIydlzYfsD09aXKx0t6Xy4
28
- 2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
- QWc=
23
+ 2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAEjpaOXHHp8s/7GL2qCb
24
+ YAs7urOLv9VHSPfQWAwaTMVnSsIf3Sw4xzISOP/mmfEPBPXtz61K5esrE/uTFtgb
25
+ FyjxQk2H0sEWgrRXGGNHBWQRhhEs7LP/TByoC15A0br++xLxRz4r7HBLGAWQQDpg
26
+ 66BJ2TBVjxS6K64tKbq7+ACyrOZGgTfNHACh4M076y0x0oRf/rwBrU39/KRfuhbb
27
+ cm+nNCEtO35gTmZ2bVDHLGvWazi3gJt6+huQjfXTCUUG2YYBxwhu+GPdAGQPxpf9
28
+ lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
+ W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2021-01-16 00:00:00.000000000 Z
31
+ date: 2021-09-06 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.5
78
+ rubygems_version: 3.2.27
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