globs 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/lib/globs/version.rb +1 -1
- data/lib/globs.rb +62 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33e33b53ea61ac120c9a50e88a9eaf5f9c59843808d5c25edf9af003d3a2b42a
|
4
|
+
data.tar.gz: 0f59998761ed6675653e669b99391283653fd6ac09579240d97a0d3c1da47e6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 756c66b3af815aab238b66ed95fb4c133bcf448933de922f4838e2255dca68db4c3f8f75850bacfe8cfc19f931671855638e062d09f636a55f6f5d01f8325396
|
7
|
+
data.tar.gz: 915e3ddc3aaf39dbc29c9bcc24fc8b7a6ffaa1210d33b6f1f3d316cee3d116272ebbd9982ddaba0b909d94cb8e4486eb6340d0af83df3fc15803c5cec36f5d29
|
data/.gitignore
CHANGED
data/lib/globs/version.rb
CHANGED
data/lib/globs.rb
CHANGED
@@ -1,8 +1,61 @@
|
|
1
1
|
require "globs/version"
|
2
2
|
|
3
|
+
# Container for Globs methods, currently only static as the public api
|
4
|
+
# footprint is relatively small.
|
5
|
+
#
|
6
|
+
# It should be noted that I'll be exceptionally verbose in the comments
|
7
|
+
# of this code as it's an interesting usecase for learning to combine
|
8
|
+
# map, flat_map, and reduce for permutation-type generators.
|
9
|
+
#
|
10
|
+
# More than likely I'll write a tutorial on how the code works later and
|
11
|
+
# link to it in these comments for the exceptionally curious. It'd be roughly
|
12
|
+
# a 2.5 / 5 for difficulty.
|
13
|
+
#
|
14
|
+
# @author baweaver
|
15
|
+
# @since 0.0.1
|
16
|
+
#
|
3
17
|
module Globs
|
4
18
|
extend self
|
5
19
|
|
20
|
+
# Shorthand for `puts expand(str)` for outputting to STDOUT for
|
21
|
+
# unix-like piping.
|
22
|
+
#
|
23
|
+
# @since 0.0.2
|
24
|
+
#
|
25
|
+
# @param string [String]
|
26
|
+
# Glob-like string to be expanded
|
27
|
+
#
|
28
|
+
# @return [NilClass]
|
29
|
+
# Only outputs to STDOUT, returning `nil` from the actual
|
30
|
+
# method call
|
31
|
+
def puts(string)
|
32
|
+
puts expand(string)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Expands a glob-like string into all possible interpretations of it.
|
36
|
+
#
|
37
|
+
# @since 0.0.1
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
#
|
41
|
+
# ```
|
42
|
+
# Globs.expand("test.{a, b}.{1, 2}.com")
|
43
|
+
# => ["test.a.1.com", "test.a.2.com", "test.b.1.com", "test.b.2.com"]
|
44
|
+
# ```
|
45
|
+
#
|
46
|
+
# @note
|
47
|
+
# While this _could_ be made into a tokenization type process for speed
|
48
|
+
# reasons there's very little reason to do so immediately. The current
|
49
|
+
# implementation is far more proof of concept than anything.
|
50
|
+
#
|
51
|
+
# If speed needs to happen to arise from usage, PRs are welcome to
|
52
|
+
# optimize this method, but the public api should remain the same.
|
53
|
+
#
|
54
|
+
# @param string [String]
|
55
|
+
# Glob-like string to be expanded
|
56
|
+
#
|
57
|
+
# @return [Array[String]]
|
58
|
+
# All expansions of the glob-like string
|
6
59
|
def expand(string)
|
7
60
|
string
|
8
61
|
.split(/\{|\}/)
|
@@ -12,6 +65,15 @@ module Globs
|
|
12
65
|
}
|
13
66
|
end
|
14
67
|
|
68
|
+
# Interprets a set of glob expressions, looking for items like ranges. When
|
69
|
+
# it finds such an item, it expands the range into an array to flatten into
|
70
|
+
# the set of possible values for a section.
|
71
|
+
#
|
72
|
+
# @param set [Array[String]]
|
73
|
+
# Unexpanded glob set
|
74
|
+
#
|
75
|
+
# @return [Array[String]]
|
76
|
+
# Fully expanded glob sets
|
15
77
|
private def interpret_glob_set(set)
|
16
78
|
set.flat_map { |s| s.include?('..') ? Range.new(*s.split('..')).to_a : s }
|
17
79
|
end
|