globs 0.0.1 → 0.0.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: 27981a3aaa22feac105986f68020cd41b1d2f38f3f4492b13405dc785539dadf
4
- data.tar.gz: 4aa999a5689ded981ae89216c066eb0c0c7b008ac509913c858e180a561d886b
3
+ metadata.gz: 33e33b53ea61ac120c9a50e88a9eaf5f9c59843808d5c25edf9af003d3a2b42a
4
+ data.tar.gz: 0f59998761ed6675653e669b99391283653fd6ac09579240d97a0d3c1da47e6d
5
5
  SHA512:
6
- metadata.gz: 82d16b20b0c77b8a94dca4e13f1ec54e677f9ebf450e99bd368ca002929ed3f524c95a28329bad58923cdfacd9654096084485826cd578893ec132b3f84d5e36
7
- data.tar.gz: 3aaf66d343ac7b5d55a7e9a2659e3aa65f1daa0f21802316ae8fbc5f26c57ad1aececcb1563481d7466cabee6d09e7b7322b70aa05a5da5110c70b57d452a06f
6
+ metadata.gz: 756c66b3af815aab238b66ed95fb4c133bcf448933de922f4838e2255dca68db4c3f8f75850bacfe8cfc19f931671855638e062d09f636a55f6f5d01f8325396
7
+ data.tar.gz: 915e3ddc3aaf39dbc29c9bcc24fc8b7a6ffaa1210d33b6f1f3d316cee3d116272ebbd9982ddaba0b909d94cb8e4486eb6340d0af83df3fc15803c5cec36f5d29
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # compiled gems
14
+ *.gem
data/lib/globs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Globs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Weaver