regex_forms 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -0
- data/lib/regex_forms/version.rb +1 -1
- data/lib/regex_forms.rb +143 -71
- data/regex_forms-0.1.0.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4b44a0a57dd727137ff57368a58972aa0d3398d8f9c72eb9ff1d254e30c01e8
|
4
|
+
data.tar.gz: 4451bc0ee7546eea0f9ae207620f6bdff6701c342d2fc8f5d6a697d9ed6c46e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2173c9f0c6625cd3a33f4b5a5b45e6ea5d87eedeb76c48c40ff7b6438d6f6df9b707ca42c2bd4bb27362139c6339351244c91585f4c07d5cb3ea685f9b273911
|
7
|
+
data.tar.gz: 4d7db76b5937286e8e7784a7d23a330f3e336ec2c7701ad7c672fb45208e1dcab007749308aba7f77aa630c9e6875af5feec7aca9675fe24149bc0194a7e6c9f
|
data/README.md
CHANGED
Binary file
|
data/lib/regex_forms/version.rb
CHANGED
data/lib/regex_forms.rb
CHANGED
@@ -1,71 +1,143 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "regex_forms/version"
|
4
|
-
|
5
|
-
module RegexForms
|
6
|
-
class Error < StandardError; end
|
7
|
-
|
8
|
-
class ValidateCPF
|
9
|
-
attr_reader :cpf
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
regex
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "regex_forms/version"
|
4
|
+
|
5
|
+
module RegexForms
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class ValidateCPF
|
9
|
+
attr_reader :cpf
|
10
|
+
|
11
|
+
def initialize(cpf)
|
12
|
+
@cpf = cpf
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate
|
16
|
+
regex_cpf(cpf)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def regex_cpf(cpf)
|
22
|
+
if @cpf.nil? || cpf.empty?
|
23
|
+
puts "Invalid"
|
24
|
+
return { cpf: cpf, validation: false, message: Error.new("CPF is nil or empty") }
|
25
|
+
end
|
26
|
+
|
27
|
+
regex = /^(?<t_1>\d{3})\.(?<t_2>\d{3})\.(?<t_3>\d{3})\-(?<t_4>\d{2})$/
|
28
|
+
if regex.match(cpf)
|
29
|
+
return { cpf: cpf, validation: true, message: "Validated CPF" }
|
30
|
+
else
|
31
|
+
return { cpf: cpf, validation: false, message: Error.new("Invalid cpf: #{cpf}") }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class ValidateCNPJ
|
37
|
+
attr_reader :cnpj
|
38
|
+
|
39
|
+
def initialize(cnpj)
|
40
|
+
@cnpj = cnpj
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate
|
44
|
+
return invalid_response("CNPJ is nil, empty, or all zeros") if invalid_cnpj?
|
45
|
+
|
46
|
+
regex = /^(?<t_1>\d{2})\.(?<t_2>\d{3})\.(?<t_3>\d{3})\/0001-(?<t_4>\d{2})$/
|
47
|
+
|
48
|
+
if regex.match(cnpj)
|
49
|
+
valid_response("Validated CNPJ")
|
50
|
+
else
|
51
|
+
invalid_response("Invalid CNPJ: #{cnpj}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def invalid_cnpj?
|
58
|
+
cnpj.nil? || cnpj.empty? || cnpj.gsub(/[^\d]/, "") == "00000000000000"
|
59
|
+
end
|
60
|
+
|
61
|
+
def valid_response(message)
|
62
|
+
{ cnpj: cnpj, validation: true, message: message }
|
63
|
+
end
|
64
|
+
|
65
|
+
def invalid_response(message)
|
66
|
+
puts "Invalid"
|
67
|
+
{ cnpj: cnpj, validation: false, message: message }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ValidatePassword
|
72
|
+
attr_accessor :password
|
73
|
+
|
74
|
+
def initialize(password)
|
75
|
+
@password = password
|
76
|
+
end
|
77
|
+
|
78
|
+
def validatePassword
|
79
|
+
return invalid_response("Password is nil, empty, or all zeros") if invalid_password
|
80
|
+
|
81
|
+
regex = /\A.*(?=.*\d)(?=.*[!@#$%^&*]).*\z/
|
82
|
+
|
83
|
+
if regex.match(password)
|
84
|
+
valid_response("Validated Password")
|
85
|
+
else
|
86
|
+
invalid_response("Must contain at least one digit and one special character: #{password}")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def valid_response(message)
|
93
|
+
{ password: password, validation: true, message: message }
|
94
|
+
end
|
95
|
+
|
96
|
+
def invalid_password
|
97
|
+
password.nil? || password.empty?
|
98
|
+
end
|
99
|
+
|
100
|
+
def invalid_response(message)
|
101
|
+
{ password: password, validation: false, message: message }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
class ValidateEmail
|
107
|
+
attr_accessor :email
|
108
|
+
|
109
|
+
def initialize(email)
|
110
|
+
@email = email
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def validateEmail
|
115
|
+
return invalid_response("Email is nil, empty") if invalid_email
|
116
|
+
|
117
|
+
regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
118
|
+
|
119
|
+
if regex.match(email)
|
120
|
+
valid_response("Validated Email")
|
121
|
+
else
|
122
|
+
invalid_response("Must be a valid email address: #{email}")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
|
129
|
+
def valid_response(message)
|
130
|
+
{ email: email, validation: true, message: message }
|
131
|
+
end
|
132
|
+
|
133
|
+
def invalid_email
|
134
|
+
email.nil? || email.empty?
|
135
|
+
end
|
136
|
+
|
137
|
+
def invalid_response(message)
|
138
|
+
{ email: email, validation: false, message: message }
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regex_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guiherme Dantas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Regex is a versatile Ruby library designed to simplify form validation
|
14
14
|
by providing a collection of regular expressions tailored for common form fields.
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- lib/regex_forms.rb
|
27
27
|
- lib/regex_forms/version.rb
|
28
|
+
- regex_forms-0.1.0.gem
|
28
29
|
- regex_forms.gemspec
|
29
30
|
- sig/regex_forms.rbs
|
30
31
|
homepage: https://github.com/Dants0/regex_forms
|