refinements 7.9.0 → 7.10.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: ba7c2934d38986ae19d3a41bdc1305164ebe2355bb30afa925eebbeb9746f962
4
- data.tar.gz: 1945d2226c6ca304aa9958635aab6a87880b66e43566691c3ab509f5b2e77f6b
3
+ metadata.gz: 2b7b36399c299675bc98b26334acc2466c5c506849e34b36534f21d2eed72e57
4
+ data.tar.gz: 0d00c8e399a0d43c21dafef5985e9d0eb51fe7d544fbe93f4d184eafa75018a8
5
5
  SHA512:
6
- metadata.gz: 34e601f3bfe0ebe6b35ddf54dea67ef9c33d7436fae5103a2ce03106a34026f1920a6f06369ba2516ceb0a550bb6868fcd5491084cca5b6dd20ed746b4772a39
7
- data.tar.gz: 8e4d5de5f29f28df044333dbaa34fb0a6d9b34911e3e911bd5593caf4dfeb52c0c0767f5a01d164542c54a4d936453b14f6131c055234a5911d73c80673c7d14
6
+ metadata.gz: 558191fc552ba160302b9189b8bd2e3ed17ceaee226426cf9453c0c65b8ca0e771b9e85be1e5453c8c1438bc52511a45afc218c72329c17570a6036b65e9f91f
7
+ data.tar.gz: 69436b5353f1541b644f9ca72346da713bd8bb1c0f9595983392881727f06ea46ecacdea1412a929981ee24e0243865c6ac9274e747f04d3584c85216e7e300b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -9,7 +9,7 @@ image::https://badge.fury.io/rb/refinements.svg[Gem Version]
9
9
  [link=https://circleci.com/gh/bkuhlmann/refinements]
10
10
  image::https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg[Circle CI Status]
11
11
 
12
- A collection of refinements (enhancements) to core Ruby objects.
12
+ A collection of refinements (enhancements) to primitive Ruby objects.
13
13
 
14
14
  toc::[]
15
15
 
@@ -95,7 +95,8 @@ require "refinements/string_ios"
95
95
 
96
96
  === Using
97
97
 
98
- Much like including/extending a module, you’ll need modify your object(s) to use the refinement(s):
98
+ Much like including/extending a module, you’ll need to modify your object(s) to use the
99
+ refinement(s):
99
100
 
100
101
  [source,ruby]
101
102
  ----
@@ -119,7 +120,7 @@ The following sections demonstrate how each refinement enriches your objects wit
119
120
 
120
121
  ===== #compress
121
122
 
122
- Removes `nil` and empty values without modifying itself.
123
+ Removes `nil` and empty values without mutating itself.
123
124
 
124
125
  [source,ruby]
125
126
  ----
@@ -130,7 +131,7 @@ example # => ["An", nil, "", "Example"]
130
131
 
131
132
  ===== #compress!
132
133
 
133
- Removes `nil` and empty values while modifying itself.
134
+ Removes `nil` and empty values while mutating itself.
134
135
 
135
136
  [source,ruby]
136
137
  ----
@@ -141,7 +142,7 @@ example # => ["An", "Example"]
141
142
 
142
143
  ===== #include
143
144
 
144
- Adds given array or elements without modifying itself.
145
+ Adds given array or elements without mutating itself.
145
146
 
146
147
  [source,ruby]
147
148
  ----
@@ -151,7 +152,7 @@ Adds given array or elements without modifying itself.
151
152
 
152
153
  ===== #exclude
153
154
 
154
- Removes given array or elements without modifying itself.
155
+ Removes given array or elements without mutating itself.
155
156
 
156
157
  [source,ruby]
157
158
  ----
@@ -236,7 +237,7 @@ example[:b] # => []
236
237
 
237
238
  ===== #except
238
239
 
239
- Answers new hash with given keys removed without modifying itself.
240
+ Answers new hash with given keys removed without mutating itself.
240
241
 
241
242
  [source,ruby]
242
243
  ----
@@ -247,7 +248,7 @@ example # => {a: 1, b: 2, c: 3}
247
248
 
248
249
  ===== #except!
249
250
 
250
- Answers new hash with given keys removed while modifying itself.
251
+ Answers new hash with given keys removed while mutating itself.
251
252
 
252
253
  [source,ruby]
253
254
  ----
@@ -258,7 +259,7 @@ example # => {c: 3}
258
259
 
259
260
  ===== #flatten_keys
260
261
 
261
- Flattens nested keys as top-level keys without modifying itself. Does not handle nested arrays,
262
+ Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays,
262
263
  though.
263
264
 
264
265
  [source,ruby]
@@ -276,7 +277,7 @@ example # => {a: {b: 1}}
276
277
 
277
278
  ===== #flatten_keys!
278
279
 
279
- Flattens nested keys as top-level keys while modifying itself. Does not handle nested arrays,
280
+ Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays,
280
281
  though.
281
282
 
282
283
  [source,ruby]
@@ -286,9 +287,31 @@ example.flatten_keys! # => {a_b: 1}
286
287
  example # => {a_b: 1}
287
288
  ----
288
289
 
290
+ ===== #stringify_keys
291
+
292
+ Converts keys to strings without mutating itself.
293
+
294
+ [source,ruby]
295
+ ----
296
+ example = {a: 1, b: 2}
297
+ example.stringify_keys # => {"a" => 1, "b" => 2}
298
+ example # => {a: 1, b: 2}
299
+ ----
300
+
301
+ ===== #stringify_keys!
302
+
303
+ Converts keys to strings while mutating itself.
304
+
305
+ [source,ruby]
306
+ ----
307
+ example = {a: 1, b: 2}
308
+ example.stringify_keys! # => {"a" => 1, "b" => 2}
309
+ example # => {"a" => 1, "b" => 2}
310
+ ----
311
+
289
312
  ===== #symbolize_keys
290
313
 
291
- Converts keys to symbols without modifying itself.
314
+ Converts keys to symbols without mutating itself.
292
315
 
293
316
  [source,ruby]
294
317
  ----
@@ -299,7 +322,7 @@ example # => {"a" => 1, "b" => 2}
299
322
 
300
323
  ===== #symbolize_keys!
301
324
 
302
- Converts keys to symbols while modifying itself.
325
+ Converts keys to symbols while mutating itself.
303
326
 
304
327
  [source,ruby]
305
328
  ----
@@ -310,7 +333,7 @@ example # => {a: 1, b: 2}
310
333
 
311
334
  ===== #deep_merge
312
335
 
313
- Merges deeply nested hashes together without modifying itself.
336
+ Merges deeply nested hashes together without mutating itself.
314
337
 
315
338
  [source,ruby]
316
339
  ----
@@ -321,7 +344,7 @@ example # => {a: "A", b: {one: "One", two: "Two"}}
321
344
 
322
345
  ===== #deep_merge!
323
346
 
324
- Merges deeply nested hashes together while modifying itself.
347
+ Merges deeply nested hashes together while mutating itself.
325
348
 
326
349
  [source,ruby]
327
350
  ----
@@ -330,9 +353,31 @@ example.deep_merge! b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
330
353
  example # => {a: "A", b: {one: 1, two: "Two"}}
331
354
  ----
332
355
 
356
+ ===== #deep_stringify_keys
357
+
358
+ Stringifies keys of nested hash without mutating itself. Does not handle nested arrays, though.
359
+
360
+ [source,ruby]
361
+ ----
362
+ example = {a: {b: 2}}
363
+ example.deep_stringify_keys # => {"a" => {"b" => 1}}
364
+ example # => {a: {b: 2}}
365
+ ----
366
+
367
+ ===== #deep_stringify_keys!
368
+
369
+ Stringifies keys of nested hash while mutating itself. Does not handle nested arrays, though.
370
+
371
+ [source,ruby]
372
+ ----
373
+ example = {a: {b: 2}}
374
+ example.deep_stringify_keys! # => {"a" => {"b" => 1}}
375
+ example # => {"a" => {"b" => 1}}
376
+ ----
377
+
333
378
  ===== #deep_symbolize_keys
334
379
 
335
- Symbolizes keys of nested hash without modifying itself. Does not handle nested arrays, though.
380
+ Symbolizes keys of nested hash without mutating itself. Does not handle nested arrays, though.
336
381
 
337
382
  [source,ruby]
338
383
  ----
@@ -343,7 +388,7 @@ example # => {"a" => {"b" => 2}}
343
388
 
344
389
  ===== #deep_symbolize_keys!
345
390
 
346
- Symbolizes keys of nested hash while modifying itself. Does not handle nested arrays, though.
391
+ Symbolizes keys of nested hash while mutating itself. Does not handle nested arrays, though.
347
392
 
348
393
  [source,ruby]
349
394
  ----
@@ -354,7 +399,8 @@ example # => {a: {b: 1}}
354
399
 
355
400
  ===== #recurse
356
401
 
357
- Applies block to nested hash. Does not handle nested arrays, though.
402
+ Recursively iterates over the hash and any hash value by applying the given block to it. Does not
403
+ handle nested arrays, though.
358
404
 
359
405
  [source,ruby]
360
406
  ----
@@ -365,7 +411,7 @@ example.recurse(&:invert) # => {{"b" => 1} => "a"}
365
411
 
366
412
  ===== #rekey
367
413
 
368
- Transforms keys per mapping (size of mapping can vary) without modifying itself.
414
+ Transforms keys per mapping (size of mapping can vary) without mutating itself.
369
415
 
370
416
  [source,ruby]
371
417
  ----
@@ -376,7 +422,7 @@ example # => {a: 1, b: 2, c: 3}
376
422
 
377
423
  ===== #rekey!
378
424
 
379
- Transforms keys per mapping (size of mapping can vary) while modifying itself.
425
+ Transforms keys per mapping (size of mapping can vary) while mutating itself.
380
426
 
381
427
  [source,ruby]
382
428
  ----
@@ -387,7 +433,7 @@ example # => {amber: 1, blue: 2, c: 3}
387
433
 
388
434
  ===== #reverse_merge
389
435
 
390
- Merges calling hash into passed in hash without modifying itself.
436
+ Merges calling hash into passed in hash without mutating itself.
391
437
 
392
438
  [source,ruby]
393
439
  ----
@@ -398,7 +444,7 @@ example # => {a: 1, b: 2}
398
444
 
399
445
  ===== #reverse_merge!
400
446
 
401
- Merges calling hash into passed in hash while modifying itself.
447
+ Merges calling hash into passed in hash while mutating itself.
402
448
 
403
449
  [source,ruby]
404
450
  ----
@@ -421,7 +467,10 @@ example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
421
467
 
422
468
  ===== Pathname
423
469
 
424
- Conversion function (refined from `Kernel`) which can cast `nil` into a pathname.
470
+ Enhances the conversion function -- refined from `Kernel` -- which casts `nil` into a pathname in
471
+ order to avoid: `TypeError (no implicit conversion of nil into String)`. The pathname is still
472
+ invalid but at least you have an instance of `Pathname`, which behaves like a _Null Object_, that
473
+ can still be used to construct a valid path.
425
474
 
426
475
  [source,ruby]
427
476
  ----
@@ -579,6 +628,19 @@ Answers string with only first letter downcased.
579
628
  "EXAMPLE".down # => "eXAMPLE"
580
629
  ----
581
630
 
631
+ ===== #indent
632
+
633
+ Answers string indented by two spaces by default.
634
+
635
+ [source,ruby]
636
+ ----
637
+ "example".indent # => " example"
638
+ "example".indent 0 # => "example"
639
+ "example".indent -1 # => "example"
640
+ "example".indent 2 # => " example"
641
+ "example".indent 3, padding: " " # => " example"
642
+ ----
643
+
582
644
  ===== #camelcase
583
645
 
584
646
  Answers a camelcased string.
@@ -40,6 +40,14 @@ module Refinements
40
40
  replace flatten_keys(prefix: prefix, delimiter: delimiter, cast: cast)
41
41
  end
42
42
 
43
+ def stringify_keys
44
+ reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
45
+ end
46
+
47
+ def stringify_keys!
48
+ replace stringify_keys
49
+ end
50
+
43
51
  def symbolize_keys
44
52
  reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
45
53
  end
@@ -64,6 +72,14 @@ module Refinements
64
72
  replace deep_merge(other)
65
73
  end
66
74
 
75
+ def deep_stringify_keys
76
+ recurse(&:stringify_keys)
77
+ end
78
+
79
+ def deep_stringify_keys!
80
+ replace deep_stringify_keys
81
+ end
82
+
67
83
  def deep_symbolize_keys
68
84
  recurse(&:symbolize_keys)
69
85
  end
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.9.0"
8
+ VERSION = "7.10.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -50,6 +50,12 @@ module Refinements
50
50
  first.downcase + self[1, size]
51
51
  end
52
52
 
53
+ def indent multiplier = 1, padding: " "
54
+ return self if multiplier.negative?
55
+
56
+ padding * multiplier + self
57
+ end
58
+
53
59
  def camelcase
54
60
  return up unless match? DELIMITERS
55
61
 
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: 7.9.0
4
+ version: 7.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
29
  QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-09-19 00:00:00.000000000 Z
31
+ date: 2020-09-27 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
metadata.gz.sig CHANGED
Binary file