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 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
- matches = self.scan(/(\{(.*?)\})/)
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*#{Regexp.escape(separator)}\s*/)}.permutations
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.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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permutations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wes Oldenbeuving