permutations 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/permutations.rb +4 -3
- data/permutations.gemspec +1 -1
- metadata +1 -1
data/lib/permutations.rb
CHANGED
@@ -17,10 +17,11 @@ module Permutations
|
|
17
17
|
module String
|
18
18
|
# Create multi-level string permutations
|
19
19
|
# "{a,b,c}{1,2,3}".permutations # => ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]
|
20
|
-
def permutations(separator=',')
|
21
|
-
|
20
|
+
def permutations(separator=',', escape_separator=true)
|
21
|
+
separator=Regexp.escape(separator) if escape_separator
|
22
|
+
matches = self.scan(/(\{\s*(.*?)\s*\})/)
|
22
23
|
substitutions = matches.map{|match| match[0]}
|
23
|
-
permutations = matches.map{|match| match[1].split(/\s*#{
|
24
|
+
permutations = matches.map{|match| match[1].split(/\s*#{separator}\s*/)}.permutations
|
24
25
|
permutations.map do |permutation|
|
25
26
|
permutated_string = self.dup
|
26
27
|
permutation.each_with_index do |choice, index|
|
data/permutations.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'permutations'
|
4
4
|
s.summary = "Permutations is a library that allows you to generate permutations from Arrays and Strings."
|
5
5
|
s.description = s.summary
|
6
|
-
s.version = '0.1.
|
6
|
+
s.version = '0.1.2'
|
7
7
|
s.date = '2010-01-21'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|