is_valid 0.0.1

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 +7 -0
  2. data/lib/is_valid.rb +32 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e96d9c1a791ba11acb379e7166358fd83dc4844413c019520b701fdf0a00ab1c
4
+ data.tar.gz: 3c16d37f4c34622d16ffb64cb038c7c7ac71624dd054adfcc3df8a3529a07e7a
5
+ SHA512:
6
+ metadata.gz: 68d7f6007244130a280d74b88a147ccef183c4e641517b5ecf30ec9ab0b690923da023c5013ff1d9ee52023af76dd92e37d7a05092bfa9ee624c4498a1c40705
7
+ data.tar.gz: ddfd8f754905aec700a0d44a96c7c739ed342dc1e1471f5cb3b3d7f545acdf28a0328f9f39ce4dc821163bffdb05d90a0ab7c7e865e1c782bd7fe2b73a3427de
data/lib/is_valid.rb ADDED
@@ -0,0 +1,32 @@
1
+ class ValidCheck
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
+ }
12
+ @rules = @rules.merge(rules)
13
+ @templates = templates
14
+ end
15
+
16
+ def check(var, rule_name)
17
+ var.to_s.match?(@rules[rule_name.to_sym])
18
+ end
19
+
20
+ def check_hash(hash_var, template)
21
+ errors = []
22
+ rules = @templates[template.to_sym]
23
+ if !rules.nil?
24
+ hash_var.each do |key, val|
25
+ errors << checked = key+' is not valid, should be '+rules[key.to_sym] if !check(val, rules[key.to_sym])
26
+ end
27
+ else
28
+ p 'template with rules does not exist'
29
+ end
30
+ res = errors.length == 0 ? true : errors
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_valid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergei Illarionov (www.butteff.ru/en/)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-04-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Ruby Gem to make a validation of a variable or a hash, based on regular
14
+ expressions or own predefined validation templates in an easy way. See full documentation
15
+ on GitHub: https://github.com/butteff/valid_check_ruby_gem'
16
+ email: butteff.ru@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/is_valid.rb
22
+ homepage: https://github.com/butteff/valid_check_ruby_gem
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.7.0
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.4.10
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Validation of a variable or a hash, based on predefined or own easy rules
45
+ test_files: []