string_pattern 1.3.2 → 1.4.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 +13 -0
  3. data/lib/string_pattern.rb +12 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b0a0136c88cca57e223f884f1ed5ad0d9484ce41a04922be2205bd252994cee
4
- data.tar.gz: dd34d0032ab5897585fcd69b48fc8a88c6becf47fb205a64586176991584e7e3
3
+ metadata.gz: c56944f9a6e4dd6c11c84813c12f02f72add7960a232c05a81aae8447aa81c71
4
+ data.tar.gz: 5bb325bfe497068222720536125816831f2bcc83a3d32cb71afc6ad5c6b2af1c
5
5
  SHA512:
6
- metadata.gz: 06f9a57bbdf7da87b5f9ca8d1fbeafcc911779e7436205ce00adde1d78829c83a313eb9509c4009df93963eae54e4966b51702d5ff58ba35969837c960dbf530
7
- data.tar.gz: 076aa53e67c1ae21e372ac56ce69931d8da7b957893cb88471bef121744189e915f8eca0a35db3e06d15cb5b9eed37fbb70a722783ce438ef2ae9fb3c18a709b
6
+ metadata.gz: e9e2f38f33d7c3bf8e9c7af925f1c1a7d92971fa7836d0860aa8e47ce5f6e81eb36becf2303d643b1e97d2ed352be759507c8463c216223a3ec0c6e51cc049ee
7
+ data.tar.gz: fa6f8de323ba93f65a0a94735d9aea799e96162f4e18406d23960f938fb90b2fa5366fb75e5e92fd24a8ca34896fc6b5a48ce4f444fb2fdb9562b473d3964ead
data/README.md CHANGED
@@ -85,6 +85,19 @@ StringPattern.dont_repeat = true #default: false
85
85
  StringPattern.cache_values = Hash.new() #to clean the generated values from memory
86
86
  ```
87
87
 
88
+ Using dont_repeat all the generated string during the current run will be unique.
89
+
90
+ In case you just want one particular string to be unique but not the rest then add to the pattern just in the end the symbol: &
91
+
92
+ The pattern needs to be a symbol object.
93
+
94
+ ```ruby
95
+ 1000.times {
96
+ puts :"6-20:L/N/&".gen #will be unique
97
+ puts :"10:N".gen
98
+ }
99
+ ```
100
+
88
101
  #### Custom characters
89
102
 
90
103
  Also, it's possible to provide the characters we want. To do that we'll use the symbol_type [characters]
@@ -669,6 +669,18 @@ class StringPattern
669
669
  good_result=true
670
670
  end
671
671
  end
672
+ if pattern.kind_of?(Symbol) and symbol_type[-1]=="&"
673
+ if @cache_values[pattern.__id__].nil?
674
+ @cache_values[pattern.__id__]=Array.new()
675
+ @cache_values[pattern.__id__].push(string)
676
+ good_result=true
677
+ elsif @cache_values[pattern.__id__].include?(string)
678
+ good_result = false
679
+ else
680
+ @cache_values[pattern.__id__].push(string)
681
+ good_result=true
682
+ end
683
+ end
672
684
  end until good_result or tries>10000
673
685
  unless good_result
674
686
  puts "Not possible to generate the string on StringPattern.generate: #{pattern.inspect}, expected_errors: #{expected_errors.inspect}"
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.3.2
4
+ version: 1.4.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-09-04 00:00:00.000000000 Z
11
+ date: 2018-09-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: You can easily generate strings supplying a very simple pattern. Also,
14
14
  you can validate if a text fulfills a specific pattern or even generate a string