string_pattern 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -0
  3. data/lib/string_pattern.rb +6 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b3cd24566b10d29d53ae0dc90ae200ff772aa2673582f46870cb6a7b10b5503
4
- data.tar.gz: dfa03622a4504169004dfae4694de64df274ac1d2977a1c1e271dd48b5aff97a
3
+ metadata.gz: 2d4c76309330e0ce36e6f110971791053f1c932a92246d30454342c58df5ca82
4
+ data.tar.gz: dd885204b85c12ce3d734187649270b5e38a6f89b7b8789a8ed5d76fb5492b80
5
5
  SHA512:
6
- metadata.gz: 92309292bf67be968e6212ab37b6a32f7019b54b7d45f71a60208cf3e5ec4a0320875cafd0bafda607dce4398daf9a480e59f6212df99bfe6c31176f620f937f
7
- data.tar.gz: dfa1507522d70a2926e783def52c32af007156592c65e4dd7f0abb3a36126e0cc5ba74c58cc2e757de2e1bd2704b7e41f2b2d75d92ca735789de31328bc93357
6
+ metadata.gz: f3dc754593a2838186535d4330eefba9e0f560a90c63f3e8981a2883498fbe5e68d325cadecaaa3993fde53e21e5c22a52b10eb3159ba44c7fa6d8c3692b8305
7
+ data.tar.gz: baee5bb1e9e032b68fb2f19f683e0b0c458d946225c0b000501f0676cde020f56ad26420e0868a7c2eada703e728043a8557b10fa622561c29f0e4aebe633651
data/README.md CHANGED
@@ -77,6 +77,8 @@ p gen "3:N"
77
77
  #>443
78
78
  ```
79
79
 
80
+ #### Generating unique strings
81
+
80
82
  If you want to generate for example 1000 strings and be sure all those strings are different you can use:
81
83
 
82
84
  ```ruby
@@ -100,6 +102,26 @@ The pattern needs to be a symbol object.
100
102
  }
101
103
  ```
102
104
 
105
+ #### How to generate one or another string
106
+
107
+ In case you need to specify that the string is generated selecting one or another fixed string or pattern, you can do it by using Array of patterns and in the position you want you can add an array with the possible values
108
+
109
+ ```ruby
110
+ p ["uno:", :"5:N", ['.red','.green', :'3:L'] ].gen
111
+
112
+ # first position a fixed string: "uno:"
113
+ # second position 5 random numbers
114
+ # third position one of these values: '.red', '.green' or 3 letters
115
+
116
+ # example output:
117
+ # 'uno:34322.red'
118
+ # 'uno:44432.green'
119
+ # 'uno:34322.red'
120
+
121
+ ```
122
+
123
+ Take in consideration that this is only available to generate successful strings but not for validation
124
+
103
125
  #### Custom characters
104
126
 
105
127
  Also, it's possible to provide the characters we want. To do that we'll use the symbol_type [characters]
@@ -296,9 +296,14 @@ class StringPattern
296
296
  if expected_errors.kind_of?(Symbol)
297
297
  expected_errors = [expected_errors]
298
298
  end
299
-
299
+
300
300
  if pattern.kind_of?(Array)
301
301
  pattern.each {|pat|
302
+
303
+ if pat.kind_of?(Array) # for the case it is one of the values
304
+ pat = pat.sample
305
+ end
306
+
302
307
  if pat.kind_of?(Symbol)
303
308
  if pat.to_s.scan(/^!?\d+-?\d*:.+/).size > 0
304
309
  string << StringPattern.generate(pat.to_s, expected_errors: expected_errors)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string_pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-21 00:00:00.000000000 Z
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'You can easily generate strings supplying a very simple pattern. ''10-20:Xn/x/''.generate
14
14
  #>qBstvc6JN8ra. Also, you can validate if a text fulfills a specific pattern or