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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3075e6ddd7fa0bbd62e52839e730525d14534e84271fd03c06dc3039a68dcd8a
4
- data.tar.gz: b9552b5043c35d4ca0fba8e0bef626edc94736ec55c9e462f2bd9312be7af8f4
3
+ metadata.gz: c4b44a0a57dd727137ff57368a58972aa0d3398d8f9c72eb9ff1d254e30c01e8
4
+ data.tar.gz: 4451bc0ee7546eea0f9ae207620f6bdff6701c342d2fc8f5d6a697d9ed6c46e3
5
5
  SHA512:
6
- metadata.gz: d9a6039f59d802716e311aa53dc576b13f427948d41f721d54fd6dc6967196a8105b58ae81c47797ea1ddd940f34ab82ac7dc2036934ebbeb259ae1d1b956a04
7
- data.tar.gz: 5ad6930a10303839d49fc9aeccf6ebc26dd511decccced96422a73115736c9471ce35c4d3c9e9ca2ef9d31b35f839537bdf35046207567122b06bfbf4509c9c5
6
+ metadata.gz: 2173c9f0c6625cd3a33f4b5a5b45e6ea5d87eedeb76c48c40ff7b6438d6f6df9b707ca42c2bd4bb27362139c6339351244c91585f4c07d5cb3ea685f9b273911
7
+ data.tar.gz: 4d7db76b5937286e8e7784a7d23a330f3e336ec2c7701ad7c672fb45208e1dcab007749308aba7f77aa630c9e6875af5feec7aca9675fe24149bc0194a7e6c9f
data/README.md CHANGED
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RegexForms
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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
- def initialize(cpf)
13
- @cpf = cpf
14
- end
15
-
16
- def validate
17
- regex_cpf(cpf)
18
- end
19
-
20
- private
21
-
22
- def regex_cpf(cpf)
23
- if @cpf.nil? || cpf.empty?
24
- puts "Invalid"
25
- return {cpf: cpf, validation: false, message: Error.new("CPF is nil or empty")}
26
- end
27
-
28
- regex = /^(?<t_1>\d{3})\.(?<t_2>\d{3})\.(?<t_3>\d{3})\-(?<t_4>\d{2})$/
29
- if regex.match(cpf)
30
- return {cpf: cpf, validation: true, message: "Validated CPF"}
31
- else
32
- return {cpf: cpf, validation: false, message: Error.new("Invalid cpf: #{cpf}")}
33
- end
34
- end
35
- end
36
-
37
- class ValidateCNPJ
38
- attr_reader :cnpj
39
-
40
- def initialize(cnpj)
41
- @cnpj = cnpj
42
- end
43
-
44
- def validate
45
- return invalid_response("CNPJ is nil, empty, or all zeros") if invalid_cnpj?
46
-
47
- regex = /^(?<t_1>\d{2})\.(?<t_2>\d{3})\.(?<t_3>\d{3})\/0001-(?<t_4>\d{2})$/
48
-
49
- if regex.match(cnpj)
50
- valid_response("Validated CNPJ")
51
- else
52
- invalid_response("Invalid CNPJ: #{cnpj}")
53
- end
54
- end
55
-
56
- private
57
-
58
- def invalid_cnpj?
59
- cnpj.nil? || cnpj.empty? || cnpj.gsub(/[^\d]/, '') == '00000000000000'
60
- end
61
-
62
- def valid_response(message)
63
- { cnpj: cnpj, validation: true, message: message }
64
- end
65
-
66
- def invalid_response(message)
67
- puts "Invalid"
68
- { cnpj: cnpj, validation: false, message: message }
69
- end
70
- end
71
- end
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.0
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-03 00:00:00.000000000 Z
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