refinements 10.1.1 → 11.0.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: 82142460f83d84a2b94bf4a1e6c07b4c6839e91f2da64192e0c64a36382fe3e5
4
- data.tar.gz: d657c64e946049d4c946513329446b781880c34c76301408318a8487e0728f17
3
+ metadata.gz: 252744b620f3c79a0c38b635157f62fc9e48527701145e871de885c547b44b61
4
+ data.tar.gz: 411b88c5cf6b9b95c59c43055b8a2402c95d9954b612837fce70a106c4c4a5f1
5
5
  SHA512:
6
- metadata.gz: 81df10e22a7fb65d5737e7a8c23114fdecd47bcdecf532bc231612d29cd9036a90444fd8d59b5d140ab7c72347a1bbbbc9dee9b1e8c3464962b146ad5dc82085
7
- data.tar.gz: 4446cffdb57fe7383f891193a95edc8c0a023da2f6670fb13a00730be21113123a55f8f13ad9cf9fad39954af418142e5e17e8b6b00cac0fb815b5ed6592252d
6
+ metadata.gz: 0c12fb201556e5949190657cd591b126115ba7efb9f14aec4aeb107455d7cd04676b0dd1cc05f84e9bdd8b7c61e2fbadbabe377b739ffd14a643c3d98d717068
7
+ data.tar.gz: db75e0359afed8603daba0bae481b8e839b9d9ede700ef22bbcde22116e2a75b221b5d56d0381500ccf992f73c11cb7a4555823c4294b131077972800a03f3c1
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -31,18 +31,34 @@ Enhances the following objects:
31
31
 
32
32
  == Setup
33
33
 
34
- To install, run:
34
+ To install _with_ security, run:
35
+
36
+ [source,bash]
37
+ ----
38
+ # 💡 Skip this line if you already have the public certificate installed.
39
+ gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
40
+ gem install refinements --trust-policy HighSecurity
41
+ ----
42
+
43
+ To install _without_ security, run:
35
44
 
36
45
  [source,bash]
37
46
  ----
38
47
  gem install refinements
39
48
  ----
40
49
 
41
- Add the following to your Gemfile file:
50
+ You can also add the gem directly to your project:
51
+
52
+ [source,bash]
53
+ ----
54
+ bundle add refinements
55
+ ----
56
+
57
+ Once the gem is installed, you only need to require it:
42
58
 
43
59
  [source,ruby]
44
60
  ----
45
- gem "refinements"
61
+ require "refinements"
46
62
  ----
47
63
 
48
64
  == Usage
@@ -262,6 +278,46 @@ needs to be a specific size with padded values.
262
278
  [1, 2].pad 3, max: 3 # [1, 2, 3]
263
279
  ----
264
280
 
281
+ ===== #pick
282
+
283
+ Answers value of first element that matches given key.
284
+
285
+ [source,ruby]
286
+ ----
287
+ array = [{name: "a", label: "A"}, {name: "b", label: "B"}, {name: "c", label: "C"}]
288
+
289
+ array.pick :name # "a"
290
+ array.pick :name, :label # ["a", "A"]
291
+ array.pick # nil
292
+ [].pick(:test) # nil
293
+ ----
294
+
295
+ ===== #pluck
296
+
297
+ Answers values of all elements that match given keys.
298
+
299
+ [source,ruby]
300
+ ----
301
+ array = [{name: "a", label: "A"}, {name: "b", label: "B"}, {name: "c", label: "C"}]
302
+
303
+ array.pluck :name # ["a", "b", "c"]
304
+ array.pluck :name, :label # [["a", "A"], ["b", "B"], ["c", "C"]]
305
+ array.pluck # []
306
+ [].pluck :test # []
307
+ ----
308
+
309
+ ===== #replace_at
310
+
311
+ Answers mutated array where an element -- at a specific index -- is replaced by single or multiple elements.
312
+
313
+ [source,ruby]
314
+ ----
315
+ %i[a b c].replace_at(0, :x) # [:x, :b, :c]
316
+ %i[a b c].replace_at(1, :x) # [:a, :x, :c]
317
+ %i[a b c].replace_at(1, :x, :y) # [:a, :x, :y, :c]
318
+ %i[a b c].replace_at(-1, :x) # [:a, :b, :x]
319
+ ----
320
+
265
321
  ===== #ring
266
322
 
267
323
  Answers a circular array which can enumerate before, current, after elements.
@@ -303,17 +359,31 @@ Answers mutated array where all target elements are replaced by single or multip
303
359
 
304
360
  ===== #to_sentence
305
361
 
306
- Answers a sentence using `", "` as the default delimiter and `"and"` as the default conjunction.
362
+ Answers a sentence using `"and"` as the default conjunction and `", "` as the default delimiter.
307
363
  Useful when building documentation, answering human readable error messages, etc.
308
364
 
309
365
  [source,ruby]
310
366
  ----
311
- [].to_sentence # ""
312
- ["test"].to_sentence # "test"
313
- ["a", :b].to_sentence # "a and b"
314
- [1, "a", :b, 2.0, /\w+/].map(&:inspect).to_sentence # 1, "a", :b, 2.0, and /\w+/
315
- %w[one two three].to_sentence # "one, two, and three"
316
- %w[eins zwei drei].to_sentence delimiter: " ", conjunction: "und" # "eins zwei und drei"
367
+ [].to_sentence # ""
368
+ ["test"].to_sentence # "test"
369
+ ["a", :b].to_sentence # "a and b"
370
+ [1, "a", :b, 2.0, /\w+/].map(&:inspect).to_sentence # 1, "a", :b, 2.0, and /\w+/
371
+ %w[one two three].to_sentence # "one, two, and three"
372
+ %w[eins zwei drei].to_sentence "und", delimiter: " " # "eins zwei und drei"
373
+ ----
374
+
375
+ ===== #to_usage
376
+
377
+ Builds upon and enhances `#to_sentence` further by answering a sentence which all elements are inspected -- where each element of the array is called with `#inspect` -- before turned into a sentence using `"and"` as the default conjunction and `", "` as the default delimiter. This is useful when providing detailed error messages _and_ you need to show the element types used.
378
+
379
+ [source,ruby]
380
+ ----
381
+ [].to_usage # ""
382
+ ["test"].to_usage # "test"
383
+ ["a", :b].to_usage # "a and b"
384
+ [1, "a", :b, 2.0, /\w+/].map(&:inspect).to_usage # 1, "a", :b, 2.0, and /\w+/
385
+ %w[one two three].to_usage # "one, two, and three"
386
+ %w[eins zwei drei].to_usage "und", delimiter: " " # "eins zwei und drei"
317
387
  ----
318
388
 
319
389
  ==== Big Decimal
@@ -813,8 +883,7 @@ Pathname.make_temp_dir { |path| path.join "sub_dir" } # Pathname:/var/fol
813
883
 
814
884
  ===== .require_tree
815
885
 
816
- Requires all files in given root path and corresponding nested tree structure. All files are sorted
817
- before being required to ensure consistent behavior. Example:
886
+ Requires all Ruby files in given root path and corresponding nested tree structure. All files are sorted before being required to ensure consistent behavior. Example:
818
887
 
819
888
  [source,ruby]
820
889
  ----
@@ -1142,11 +1211,11 @@ Answers indentation (string) which is the result of the multiplier times padding
1142
1211
 
1143
1212
  [source,ruby]
1144
1213
  ----
1145
- "example".indent # " example"
1146
- "example".indent 0 # "example"
1147
- "example".indent -1 # "example"
1148
- "example".indent 2 # " example"
1149
- "example".indent 3, padding: " " # " example"
1214
+ "example".indent # " example"
1215
+ "example".indent 0 # "example"
1216
+ "example".indent -1 # "example"
1217
+ "example".indent 2 # " example"
1218
+ "example".indent 3, pad: " " # " example"
1150
1219
  ----
1151
1220
 
1152
1221
  ===== #last
@@ -33,6 +33,29 @@ module Refinements
33
33
 
34
34
  def pad(value, max: size) = dup.fill(value, size..(max - 1))
35
35
 
36
+ def pick(*keys)
37
+ return if empty?
38
+
39
+ keys.many? ? keys.map { |key| first[key] } : first[keys.first]
40
+ end
41
+
42
+ def pluck(*keys)
43
+ return dup if empty?
44
+ return [] if keys.empty?
45
+
46
+ if keys.many?
47
+ map { |element| keys.map { |key| element[key] } }
48
+ else
49
+ key = keys.first
50
+ map { |element| element[key] }
51
+ end
52
+ end
53
+
54
+ def replace_at(index, *elements)
55
+ delete_at index
56
+ insert(index, *elements)
57
+ end
58
+
36
59
  def ring(&) = [last, *self, first].each_cons(3, &)
37
60
 
38
61
  def supplant target, *replacements
@@ -49,13 +72,17 @@ module Refinements
49
72
  self
50
73
  end
51
74
 
52
- def to_sentence delimiter: ", ", conjunction: "and"
75
+ def to_sentence conjunction = "and", delimiter: ", "
53
76
  case length
54
77
  when (3..) then "#{self[..-2].join delimiter}#{delimiter}#{conjunction} #{last}"
55
78
  when 2 then join " #{conjunction} "
56
79
  else join
57
80
  end
58
81
  end
82
+
83
+ def to_usage conjunction = "and", delimiter: ", "
84
+ map(&:inspect).to_sentence conjunction, delimiter:
85
+ end
59
86
  end
60
87
  end
61
88
  end
@@ -24,9 +24,7 @@ module Refinements
24
24
  end
25
25
  end
26
26
 
27
- def require_tree root, pattern = "**/*.rb"
28
- new(root).files(pattern).each { |path| require path.to_s }
29
- end
27
+ def require_tree(root) = new(root).files("**/*.rb").each { |path| require path.to_s }
30
28
 
31
29
  def root = new(File::SEPARATOR)
32
30
  end
@@ -26,8 +26,8 @@ module Refinements
26
26
  self[..(maximum - 1)]
27
27
  end
28
28
 
29
- def indent multiplier = 1, padding: " "
30
- multiplier.negative? ? self : (padding * multiplier) + self
29
+ def indent multiplier = 1, pad: " "
30
+ multiplier.negative? ? self : (pad * multiplier) + self
31
31
  end
32
32
 
33
33
  def last minimum = 0
data/refinements.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "refinements"
5
- spec.version = "10.1.1"
5
+ spec.version = "11.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/refinements"
9
- spec.summary = "A collection of refinements to core Ruby objects."
9
+ spec.summary = "A collection of core Ruby object refinements."
10
10
  spec.license = "Hippocratic-2.1"
11
11
 
12
12
  spec.metadata = {
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: 10.1.1
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-04-08 00:00:00.000000000 Z
38
+ date: 2023-06-13 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email:
@@ -90,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.4.10
93
+ rubygems_version: 3.4.14
94
94
  signing_key:
95
95
  specification_version: 4
96
- summary: A collection of refinements to core Ruby objects.
96
+ summary: A collection of core Ruby object refinements.
97
97
  test_files: []
metadata.gz.sig CHANGED
Binary file