nice_hash 1.15.6 → 1.16.0

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: d93166bb9591cd912ef6fbd380b25f6af2937c71478abd631e2ffc44b937e19a
4
- data.tar.gz: a2db067687093c6ab4d3b193fe1d7575af33f2c0e34f8092f0103064117edd95
3
+ metadata.gz: 4894f796091ce28510214b7758d52d40f40547a781c81b9d75a57b8e3c50bcfa
4
+ data.tar.gz: a6656db5d796ad0366421036bd5bd7a1646bbe6226b3bd53500e2a214fd7d3c3
5
5
  SHA512:
6
- metadata.gz: 363546839964322abe945dc6cacb9ff8a8ae7bf8301e0ec087429b2fd6a503ff417637591e7fb97cb13e792ca2b405efef8ee5585001c750b6f763156244b756
7
- data.tar.gz: 0e9e34a219d43ff42cd387e1a48dc0009db5890ed6d09c48330a5ab0089e75588e1cc03c011d550f4fc90a3fd30e2041392b117b26678f6febe3e56cf0eef491
6
+ metadata.gz: c75cefbfbabbe7d018c53ba333a5fe88b525c8ec4c094ae876edc9fd6bee94e593f5ccce4896407c25be009c427bf2af0f2ee2b86ce23720b3fe0766254a11fb
7
+ data.tar.gz: f1e6b4ccfa0706728962c55d2e928bf16690dff926d512cc658729b57ae6e21b7c470019c96897eae3f39935353c9d9f2e1291578a92b898da8aa8ee37a60701
data/README.md CHANGED
@@ -116,7 +116,8 @@ my_hash={
116
116
  country: {default: 'Spain', correct: ["Spain", "Iceland", "Serbia", "Denmark", "Canada", "Italy", "Austria"].join("|")}, #one of these values
117
117
  mobilePhone: {default: '(987)654321', correct: ['(', :'3:N', ')', :'6-8:N']},
118
118
  sex: :"male|female|other", #any of these values
119
- display: true
119
+ display: true,
120
+ user_names: [ :'3-10:L' ]
120
121
  }
121
122
  ```
122
123
 
@@ -138,6 +139,7 @@ Explanations of the different fields:
138
139
  country: correct: one of these values "Spain", "Iceland", "Serbia", "Denmark", "Canada", "Italy", "Austria"
139
140
  mobilePhone: correct: a sting pattern with one of the next: "(nnn) nnnnnn", "(nnn) nnnnnnn", "(nnn) nnnnnnnn"
140
141
  sex: 'male' or 'female' or 'other'
142
+ user_names: array of strings from 3 to 10 letters
141
143
 
142
144
  So in case you want to assign to a key a string pattern value like for example in loginame, you need to specify the string pattern as a symbol :"5-10:/xn/"
143
145
 
@@ -303,7 +305,8 @@ On this example new_hash will contain:
303
305
  country: ["Spain", "Iceland", "Serbia", "Denmark", "Canada", "Italy", "Austria"].join("|"), #one of these values
304
306
  mobilePhone: ['(', :'3:N', ')', :'6-8:N'],
305
307
  sex: :"male|female|other", #any of these values
306
- display: true
308
+ display: true,
309
+ user_names: [ :'3-10:L' ]
307
310
  }
308
311
  ```
309
312
 
@@ -383,7 +386,9 @@ In case of filtering by :correct new_hash would have a value like this for examp
383
386
  :country=>"Denmark",
384
387
  :mobilePhone=>"(707)8782080",
385
388
  :sex=>"male",
386
- :display=>true}
389
+ :display=>true,
390
+ :user_names=>["FFrriNdw", "ACc"]
391
+ }
387
392
  ```
388
393
 
389
394
  In case no filtering you will get all the values for all keys
@@ -438,7 +443,9 @@ On this example wrong_min_length will contain something like:
438
443
  :country=>"Spai",
439
444
  :mobilePhone=>"(237)17640431",
440
445
  :sex=>"mal",
441
- :display=>true}
446
+ :display=>true,
447
+ :user_names=>["FF"]
448
+ }
442
449
  ```
443
450
 
444
451
  ### Return the select_fields or the pattern_fields
@@ -488,7 +495,8 @@ all_pattern_fields contains:
488
495
  [:draws, 1, :drawName],
489
496
  [:draws, 1, :owner, :correct],
490
497
  [:zip, :correct],
491
- [:mobilePhone, :correct]]
498
+ [:mobilePhone, :correct]],
499
+ [:user_names]
492
500
  ```
493
501
 
494
502
  pattern_fields_on_correct contains:
@@ -504,7 +512,8 @@ pattern_fields_on_correct contains:
504
512
  [:draws, 1, :drawName],
505
513
  [:draws, 1, :owner],
506
514
  [:zip],
507
- [:mobilePhone]]
515
+ [:mobilePhone]],
516
+ [:user_names]
508
517
  ```
509
518
 
510
519
 
@@ -582,7 +591,9 @@ After using the bury method default_values will contain:
582
591
  :country=>"Spain",
583
592
  :mobilePhone=>"(987)654321",
584
593
  :sex=>"male",
585
- :display=>true}
594
+ :display=>true,
595
+ :user_names=>["FFrriNdw", "ACc"]
596
+ }
586
597
  ```
587
598
 
588
599
  ### Validating hashes
@@ -620,7 +631,9 @@ values = {
620
631
  :country=>"Iceland",
621
632
  :mobilePhone=>"(441)97037845",
622
633
  :sex=>"male",
623
- :display=>true}
634
+ :display=>true,
635
+ :user_names=>['ddfdsa']
636
+ }
624
637
  ```
625
638
 
626
639
  To validate those values against the patterns defined on my_hash:
@@ -801,6 +814,8 @@ The last parameter (patterns) allow you to add verification of data values follo
801
814
  Valid patterns:
802
815
  - a regular expression
803
816
  - any string_pattern, more info: string_pattern project: https://github.com/MarioRuiz/string_pattern
817
+ - array of a string_pattern:
818
+ - [ :'10-20:L' ]
804
819
  - Boolean: specifying Boolean will check if the value is TrueClass or FalseClass
805
820
  - ranges: Any kind of numeric ranges, for example:
806
821
  - 10..400
@@ -111,13 +111,24 @@ class NiceHash
111
111
  end
112
112
  elsif value.kind_of?(Array)
113
113
  array_pattern = false
114
- value.each { |v|
114
+ if value.size == 1
115
+ v = value[0]
115
116
  if (v.kind_of?(String) or v.kind_of?(Symbol)) and StringPattern.analyze(v, silent: true).kind_of?(StringPattern::Pattern)
116
- hashv[key] = StringPattern.generate(value, expected_errors: expected_errors)
117
+ hashv[key] = []
118
+ (rand(5)+1).times do
119
+ hashv[key]<<StringPattern.generate(v, expected_errors: expected_errors)
120
+ end
117
121
  array_pattern = true
118
- break
119
122
  end
120
- }
123
+ else
124
+ value.each { |v|
125
+ if (v.kind_of?(String) or v.kind_of?(Symbol)) and StringPattern.analyze(v, silent: true).kind_of?(StringPattern::Pattern)
126
+ hashv[key] = StringPattern.generate(value, expected_errors: expected_errors)
127
+ array_pattern = true
128
+ break
129
+ end
130
+ }
131
+ end
121
132
  unless array_pattern
122
133
  value_ret = Array.new
123
134
  value.each { |v|
@@ -93,10 +93,18 @@ class NiceHash
93
93
  results[key] = false unless value.to_s == values[key].to_s
94
94
  end
95
95
  elsif value.kind_of?(Range)
96
- if values[key].class != value.first.class or values[key].class != value.last.class
97
- results[key] = false
98
- elsif values[key] < value.first or values[key] > value.last
99
- results[key] = false
96
+ if value.size.to_s == 'Infinity'
97
+ if values[key].class != value.first.class
98
+ results[key] = false
99
+ elsif values[key] < value.first
100
+ results[key] = false
101
+ end
102
+ else
103
+ if values[key].class != value.first.class or values[key].class != value.last.class
104
+ results[key] = false
105
+ elsif values[key] < value.first or values[key] > value.last
106
+ results[key] = false
107
+ end
100
108
  end
101
109
  elsif value.kind_of?(Class) and value == DateTime
102
110
  if values[key].is_a?(String) and values[key].size == 24
@@ -118,8 +126,19 @@ class NiceHash
118
126
  complex_data = false
119
127
  value.each { |v|
120
128
  if (v.kind_of?(String) or v.kind_of?(Symbol)) and StringPattern.analyze(v, silent: true).kind_of?(StringPattern::Pattern)
121
- res = StringPattern.validate(pattern: value, text: values[key])
122
- results[key] = res if res == false
129
+ if value.is_a?(Array) and value.size == 1 and values[key].is_a?(Array)
130
+ results[key] ||= []
131
+ values[key].each do |vk|
132
+ res = StringPattern.validate(pattern: value[0], text: vk)
133
+ results[key] << res
134
+ end
135
+ if results[key].flatten.size == 0
136
+ results.delete(key)
137
+ end
138
+ else
139
+ res = StringPattern.validate(pattern: value, text: values[key])
140
+ results[key] = res if res == false
141
+ end
123
142
  array_pattern = true
124
143
  break
125
144
  elsif v.kind_of?(Hash) or v.kind_of?(Array) or v.kind_of?(Struct)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.6
4
+ version: 1.16.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: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string_pattern
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2.2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 2.2.1
22
+ version: 2.2.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '2.2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 2.2.1
32
+ version: 2.2.2
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement