is_valid 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of is_valid might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/is_valid.rb +38 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c691bffb4c4189802cdae9bf3e0235c80e09bfacf1d4f77ba47e53c5208fa625
|
4
|
+
data.tar.gz: 8954572dad1edcf70b1204a5ae944aff237e50259ef755ca8a423b0e066cccd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b460a5344b0e6949547579abb61d2bcc8a1697359382f6d909c239a3c29b47744da1298301b0ec14d59f0f0a9144c4991661c6b632bd47b7013a65cf3e8b6ae6
|
7
|
+
data.tar.gz: 3ed78bb904d4b325940269c34d20a4fb118d81a93648a7030b89800f9f1ae64bca3947380230f3dd35e50fd441200af9a870b45e1c180b2f64c7e5671ae08d66
|
data/lib/is_valid.rb
CHANGED
@@ -1,42 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class IsValid
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
def initialize(templates = {}, rules = {})
|
5
|
+
@rules = {
|
6
|
+
integer: '^(\d)+$',
|
7
|
+
float: '^(\d)+.(\d)+$',
|
8
|
+
float_with_comma: '^(\d)+,(\d)+$',
|
9
|
+
word: '^(\w)+$',
|
10
|
+
words: '^(\w| )+$',
|
11
|
+
sentence: '^(\w| |,)+(\.|!|\?)$',
|
12
|
+
boolean: '^(1|0|true|false)$',
|
13
|
+
url: '^(http://|https://)(.)+\.(.)+$',
|
14
|
+
email: '^([a-z,A-Z,\-,\_,\.]*)@(.*)+\.(.*)$',
|
15
|
+
any: '(.*)+',
|
16
|
+
nil: nil
|
17
|
+
}
|
18
|
+
@rules = @rules.merge(rules)
|
19
|
+
@templates = templates
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
if !res
|
25
|
-
res = @rules[rule_name.to_sym].nil? ? var.nil? : var.to_s.match?(@rules[rule_name.to_sym])
|
26
|
-
end
|
27
|
-
res
|
22
|
+
def check(var, rule_name)
|
23
|
+
if rule_name[-1] == '*'
|
24
|
+
rule_name = rule_name[0..-2]
|
25
|
+
res = var.nil?
|
28
26
|
end
|
27
|
+
res ||= @rules[rule_name.to_sym].nil? ? var.nil? : var.to_s.match?(@rules[rule_name.to_sym])
|
28
|
+
res
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
res = errors.length == 0 ? true : errors
|
31
|
+
def check_hash(hash_var, template)
|
32
|
+
errors = []
|
33
|
+
rules = @templates[template.to_sym]
|
34
|
+
if !rules.nil?
|
35
|
+
hash_var.each do |key, val|
|
36
|
+
errors << "#{key} is not valid, should be #{rules[key.to_sym]}" unless check(val, rules[key.to_sym])
|
37
|
+
end
|
38
|
+
else
|
39
|
+
p 'template with rules does not exist'
|
41
40
|
end
|
42
|
-
|
41
|
+
errors.empty? ? true : errors
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: is_valid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Illarionov (www.butteff.ru/en/)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby Gem to make a validation of a variable or a hash, based on regular
|
14
14
|
expressions or own predefined validation templates in an easy way. See full documentation
|