refinements 7.6.0 → 7.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -2
- data.tar.gz.sig +0 -0
- data/README.adoc +24 -0
- data/lib/refinements.rb +1 -0
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/pathnames.rb +8 -4
- data/lib/refinements/string_ios.rb +13 -0
- data/lib/refinements/strings.rb +7 -4
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b7d7affd4176bb25ee87d3718b592a0bd2b07be2bad86d584f06f0d16dcd866
|
4
|
+
data.tar.gz: 256ab9f274581c668a06949a41501c50885f9681dd6150c9b58046d59cf87de7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 356b4ea5575bbec34d4b2c31495c59b49ce9efe00bedcce194d458c8bdbbcf47ca87e3be00b60f910af14e2768cf8b42de909fcdec652a895d8de706652e0777
|
7
|
+
data.tar.gz: 0a7d8c6bd99585868ec7b2d119f7014e1c2ebf571324d23c8be209bd364417c4106f465a4f0dd6ab012fb6f82e1024ae803ef0d27949051e6c65b4aa2d6f63dd
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
ǧ6�kQ)õ���;+���GOD��tw�ůlV�� j���i��z`���)&�&�`�t�'������rY��O���vb�A�/b]���?B_DR#S��V�w��c�(�C�ӯn�?�r�։������VC�Sw)�{Їa$c~#��}� �Ow&�#;�">��"B�Cm��l9��=i�o��
|
1
|
+
���.����Q~ҵᮺiÆV��<gS�:�8������f��@J�/�'�D�}*��O$���Br
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -52,6 +52,8 @@ file for manipulation and immediate writing back to the same file.
|
|
52
52
|
** `#directories` - Answers all or filtered directories for current path.
|
53
53
|
** `#extensions` - Answers file extensions as an array.
|
54
54
|
** `#files` - Answers all or filtered files for current path.
|
55
|
+
** `#gsub` - Same behavior as `String#gsub` but answers a path with patterns replaced with desired
|
56
|
+
substitutes.
|
55
57
|
** `#relative_parent_from` - Answers relative path from parent directory. This is a complement to
|
56
58
|
`#relative_path_from`.
|
57
59
|
** `#make_ancestors` - Ensures all ancestor directories are created for a path.
|
@@ -69,6 +71,8 @@ manipulation and immediate writing back to the same file.
|
|
69
71
|
** `#snakecase` - Answers a snakecased string.
|
70
72
|
** `#titleize` - Answers titleized string.
|
71
73
|
** `#to_bool` - Answers string as a boolean.
|
74
|
+
* *String IOs*:
|
75
|
+
** `#reread` - Answers full string by rewinding to beginning of string and reading all content.
|
72
76
|
|
73
77
|
== Requirements
|
74
78
|
|
@@ -287,11 +291,16 @@ Pathname("input.txt").copy Pathname("output.txt")
|
|
287
291
|
|
288
292
|
Pathname("/example").directories # => [Pathname("a"), Pathname("b")]
|
289
293
|
Pathname("/example").directories "a*" # => [Pathname("a")]
|
294
|
+
Pathname("/example").directories flag: File::FNM_DOTMATCH # => [Pathname(".."), Pathname(".")]
|
290
295
|
|
291
296
|
Pathname("example.txt.erb").extensions # => [".txt", ".erb"]
|
292
297
|
|
293
298
|
Pathname("/example").files # => [Pathname("a.txt"), Pathname("a.png")]
|
294
299
|
Pathname("/example").files "*.png" # => [Pathname("a.png")]
|
300
|
+
Pathname("/example").files flag: File::FNM_DOTMATCH # => [Pathname(".ruby-version")]
|
301
|
+
|
302
|
+
Pathname("/a/path/some/path").gsub("path", "test") # => Pathname("/a/test/some/test")
|
303
|
+
Pathname("/%placeholder%/some/%placeholder%").gsub("%placeholder%", "test") # => Pathname("/test/some/test")
|
295
304
|
|
296
305
|
Pathname("/one/two/three").relative_parent_from("/one") # => Pathname "two"
|
297
306
|
|
@@ -334,6 +343,21 @@ Pathname("example.txt").touch at: Time.now - 1
|
|
334
343
|
"example".to_bool # => false
|
335
344
|
----
|
336
345
|
|
346
|
+
==== String IO
|
347
|
+
|
348
|
+
[source,ruby]
|
349
|
+
----
|
350
|
+
io = StringIO.new
|
351
|
+
io.write "This is a test."
|
352
|
+
io.reread # => "This is a test."
|
353
|
+
|
354
|
+
io.reread(4) => "This"
|
355
|
+
|
356
|
+
buffer = "".dup
|
357
|
+
io.reread(buffer: buffer)
|
358
|
+
buffer # => "This is a test."
|
359
|
+
----
|
360
|
+
|
337
361
|
== Tests
|
338
362
|
|
339
363
|
To test, run:
|
data/lib/refinements.rb
CHANGED
data/lib/refinements/identity.rb
CHANGED
@@ -23,16 +23,20 @@ module Refinements
|
|
23
23
|
self
|
24
24
|
end
|
25
25
|
|
26
|
-
def directories pattern = "*"
|
27
|
-
glob(pattern).select(&:directory?).sort
|
26
|
+
def directories pattern = "*", flag: File::FNM_SYSCASE
|
27
|
+
glob(pattern, flag).select(&:directory?).sort
|
28
28
|
end
|
29
29
|
|
30
30
|
def extensions
|
31
31
|
basename.to_s.split(/(?=\.)+/).tap(&:shift)
|
32
32
|
end
|
33
33
|
|
34
|
-
def files pattern = "*"
|
35
|
-
glob(pattern).select(&:file?).sort
|
34
|
+
def files pattern = "*", flag: File::FNM_SYSCASE
|
35
|
+
glob(pattern, flag).select(&:file?).sort
|
36
|
+
end
|
37
|
+
|
38
|
+
def gsub pattern, replacement
|
39
|
+
self.class.new to_s.gsub(pattern, replacement)
|
36
40
|
end
|
37
41
|
|
38
42
|
def relative_parent_from root
|
data/lib/refinements/strings.rb
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
|
3
3
|
module Refinements
|
4
4
|
module Strings
|
5
|
+
DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+).freeze
|
6
|
+
|
5
7
|
refine String.singleton_class do
|
6
8
|
def delimiters
|
7
|
-
|
9
|
+
warn "[DEPRECATION]: .delimiters is deprecated, use DELIMITERS instead."
|
10
|
+
DELIMITERS
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
@@ -48,7 +51,7 @@ module Refinements
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def camelcase
|
51
|
-
return up unless match?
|
54
|
+
return up unless match? DELIMITERS
|
52
55
|
|
53
56
|
split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :up, "::" }
|
54
57
|
.then { |text| text.split(/\s*_\s*|\s+/) }
|
@@ -56,7 +59,7 @@ module Refinements
|
|
56
59
|
end
|
57
60
|
|
58
61
|
def snakecase
|
59
|
-
return downcase unless match?
|
62
|
+
return downcase unless match? DELIMITERS
|
60
63
|
|
61
64
|
split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :down, "/" }
|
62
65
|
.then { |text| text.split(/(?=[A-Z])|\s*_\s*|\s+/) }
|
@@ -64,7 +67,7 @@ module Refinements
|
|
64
67
|
end
|
65
68
|
|
66
69
|
def titleize
|
67
|
-
return capitalize unless match?
|
70
|
+
return capitalize unless match? DELIMITERS
|
68
71
|
|
69
72
|
split(/(?=[A-Z])|\s*_\s*|\s*-\s*|\s+/).then { |parts| combine parts, :up, " " }
|
70
73
|
.then { |text| text.split %r(\s*/\s*|\s*:+\s*) }
|
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.
|
4
|
+
version: 7.7.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-
|
31
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
32
32
|
dependencies:
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler-audit
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- lib/refinements/hashes.rb
|
246
246
|
- lib/refinements/identity.rb
|
247
247
|
- lib/refinements/pathnames.rb
|
248
|
+
- lib/refinements/string_ios.rb
|
248
249
|
- lib/refinements/strings.rb
|
249
250
|
homepage: https://www.alchemists.io/projects/refinements
|
250
251
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|