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.

Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/is_valid.rb +38 -37
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 032d77e1a14f13ad4103d6f00c3897d78938c550a12cb01f2dd005f87a3cdb7f
4
- data.tar.gz: d5f557d406a222d5de8539d018335f9292b902ddba50a6fb76ef713e76dcc22e
3
+ metadata.gz: c691bffb4c4189802cdae9bf3e0235c80e09bfacf1d4f77ba47e53c5208fa625
4
+ data.tar.gz: 8954572dad1edcf70b1204a5ae944aff237e50259ef755ca8a423b0e066cccd9
5
5
  SHA512:
6
- metadata.gz: f1e1b7cd6f7d6439436c427d42f398aa845a2ea3220b67c52956b714cf39748647d899f38b29e3484a841710b43e979feda56d80fcb2caa0d60be626e5722e3a
7
- data.tar.gz: 6a601f0255b15fe7289ab09d1b771e75c269d39107dda6ef21626d5b26d380a944e5353433ed4b579b7e7f136d87cd32c7ec7ac12aff7a92e9301a9858d41e97
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
- def initialize(templates={}, rules={})
3
- @rules = {
4
- integer: '^(\d)+$',
5
- float: '^(\d)+,(\d)+$',
6
- word: '^(\w)+$',
7
- words: '^(\w| )+$',
8
- sentence: '^(\w| |,)+(\.|!|\?)$',
9
- boolean: '^(1|0|true|false)$',
10
- url: '^(http://|https://)(.)+\.(.)+$',
11
- email: '^([a-z,A-Z,\-,\_,\.]*)@(.*)+\.(.*)$',
12
- any: '(.*)+',
13
- nil: nil
14
- }
15
- @rules = @rules.merge(rules)
16
- @templates = templates
17
- end
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
- def check(var, rule_name)
20
- if rule_name[-1] == '*'
21
- rule_name = rule_name[0..-2]
22
- res = var.nil?
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
- def check_hash(hash_var, template)
31
- errors = []
32
- rules = @templates[template.to_sym]
33
- if !rules.nil?
34
- hash_var.each do |key, val|
35
- errors << checked = key+' is not valid, should be '+rules[key.to_sym] if !check(val, rules[key.to_sym])
36
- end
37
- else
38
- p 'template with rules does not exist'
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
- end
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.9
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-04-20 00:00:00.000000000 Z
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