lite-validators 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.fasterer.yml +19 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +31 -0
  6. data/.travis.yml +24 -0
  7. data/CHANGELOG.md +11 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +6 -0
  10. data/Gemfile.lock +128 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +88 -0
  13. data/Rakefile +8 -0
  14. data/_config.yml +1 -0
  15. data/bin/console +15 -0
  16. data/bin/setup +8 -0
  17. data/config/locales/en.yml +23 -0
  18. data/docs/ALPHA.md +29 -0
  19. data/docs/ALPHA_NUMERIC.md +29 -0
  20. data/docs/BASE64.md +18 -0
  21. data/docs/BOOLEAN.md +19 -0
  22. data/docs/COMPARE.md +30 -0
  23. data/docs/COORDINATE.md +27 -0
  24. data/docs/CREDIT_CARD.md +29 -0
  25. data/docs/CSV.md +44 -0
  26. data/docs/CURRENCY.md +18 -0
  27. data/docs/CUSIP.md +20 -0
  28. data/docs/EMAIL.md +26 -0
  29. data/docs/FILE_CONTENT_TYPE.md +26 -0
  30. data/docs/FILE_EXTENSION.md +25 -0
  31. data/docs/FILE_SIZE.md +38 -0
  32. data/docs/HEX.md +18 -0
  33. data/docs/IMEI.md +20 -0
  34. data/docs/IP_ADDRESS.md +26 -0
  35. data/docs/ISBN.md +18 -0
  36. data/docs/ISIN.md +20 -0
  37. data/docs/MAC_ADDRESS.md +21 -0
  38. data/docs/NAME.md +18 -0
  39. data/docs/PASSWORD.md +26 -0
  40. data/docs/PHONE_NUMBER.md +18 -0
  41. data/docs/SEDOL.md +20 -0
  42. data/docs/SLUG.md +18 -0
  43. data/docs/SSN.md +18 -0
  44. data/docs/TIME_ZONE.md +17 -0
  45. data/docs/TYPE.md +28 -0
  46. data/docs/URL.md +28 -0
  47. data/docs/USERNAME.md +18 -0
  48. data/docs/UUID.md +28 -0
  49. data/lib/lite/validators/alpha_numeric_validator.rb +11 -0
  50. data/lib/lite/validators/alpha_validator.rb +34 -0
  51. data/lib/lite/validators/base64_validator.rb +9 -0
  52. data/lib/lite/validators/base_validator.rb +54 -0
  53. data/lib/lite/validators/boolean_validator.rb +15 -0
  54. data/lib/lite/validators/compare_validator.rb +41 -0
  55. data/lib/lite/validators/coordinate_validator.rb +37 -0
  56. data/lib/lite/validators/credit_card_validator.rb +144 -0
  57. data/lib/lite/validators/csv_validator.rb +73 -0
  58. data/lib/lite/validators/currency_validator.rb +7 -0
  59. data/lib/lite/validators/cusip_validator.rb +27 -0
  60. data/lib/lite/validators/email_validator.rb +19 -0
  61. data/lib/lite/validators/file_content_type_validator.rb +38 -0
  62. data/lib/lite/validators/file_extension_validator.rb +41 -0
  63. data/lib/lite/validators/file_size_validator.rb +75 -0
  64. data/lib/lite/validators/hex_validator.rb +7 -0
  65. data/lib/lite/validators/imei_validator.rb +27 -0
  66. data/lib/lite/validators/ip_address_validator.rb +39 -0
  67. data/lib/lite/validators/isbn_validator.rb +16 -0
  68. data/lib/lite/validators/isin_validator.rb +36 -0
  69. data/lib/lite/validators/mac_address_validator.rb +18 -0
  70. data/lib/lite/validators/name_validator.rb +7 -0
  71. data/lib/lite/validators/password_validator.rb +29 -0
  72. data/lib/lite/validators/phone_number_validator.rb +7 -0
  73. data/lib/lite/validators/sedol_validator.rb +23 -0
  74. data/lib/lite/validators/slug_validator.rb +7 -0
  75. data/lib/lite/validators/ssn_validator.rb +7 -0
  76. data/lib/lite/validators/time_zone_validator.rb +13 -0
  77. data/lib/lite/validators/type_validator.rb +41 -0
  78. data/lib/lite/validators/url_validator.rb +61 -0
  79. data/lib/lite/validators/username_validator.rb +7 -0
  80. data/lib/lite/validators/uuid_validator.rb +37 -0
  81. data/lib/lite/validators/version.rb +9 -0
  82. data/lib/lite/validators.rb +12 -0
  83. data/lite-validators.gemspec +51 -0
  84. metadata +265 -0
@@ -0,0 +1,29 @@
1
+ # Credit card
2
+
3
+ #### Rules
4
+
5
+ The rules are for length and prefixes are dynamic based on the provider
6
+ [view list](https://github.com/drexed/lite-validators/blob/master/lib/lite/validators/credit_card_validator.rb).
7
+
8
+ ```ruby
9
+ # 1. Length
10
+ # 2. Prefix
11
+ # 3. Checksum
12
+ ```
13
+
14
+ #### Options
15
+
16
+ Option | Type | Available | Default
17
+ --- | --- | --- | ---
18
+ provider | symbol | [view here](https://github.com/drexed/lite-validators/blob/master/lib/lite/validators/credit_card_validator.rb) | all
19
+
20
+ #### Usage
21
+
22
+ ```ruby
23
+ class User < ActiveRecord::Base
24
+
25
+ validates :input_0, credit_card: true
26
+ validates :input_1, credit_card: { provider: :visa }
27
+
28
+ end
29
+ ```
data/docs/CSV.md ADDED
@@ -0,0 +1,44 @@
1
+ # CSV
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Dimension
7
+ :columns
8
+ :rows
9
+
10
+ # 2. Check
11
+ :in => '==='
12
+ :less_than => '<'
13
+ :less_than_or_equal_to => '<='
14
+ :greater_than => '>'
15
+ :greater_than_or_equal_to => '>='
16
+ :equal_to => '=='
17
+ :not_equal_to => '!='
18
+ ```
19
+
20
+ #### Options
21
+
22
+ Option | Type | Available | Default
23
+ --- | --- | --- | ---
24
+ columns | hash | |
25
+ rows | hash | |
26
+ in | range | |
27
+ less_than | numeric | |
28
+ less_than_or_equal_to | numeric | |
29
+ greater_than | numeric | |
30
+ greater_than_or_equal_to | numeric | |
31
+ equal_to | numeric | |
32
+ not_equal_to | numeric | |
33
+
34
+ #### Usage
35
+
36
+ ```ruby
37
+ class User < ActiveRecord::Base
38
+
39
+ validates :input_0, csv: { columns: { less_than: 100 } }
40
+ validates :input_1, csv: { rows: { in: (50..100) } }
41
+ validates :input_2, csv: { columns: { equal_to: 5 }, rows: { greater_than: 5 } }
42
+
43
+ end
44
+ ```
data/docs/CURRENCY.md ADDED
@@ -0,0 +1,18 @@
1
+ # Currency
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^\d*+(\.\d{1,2})$/
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, currency: true
16
+
17
+ end
18
+ ```
data/docs/CUSIP.md ADDED
@@ -0,0 +1,20 @@
1
+ # CUSIP
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^[0-9A-Z]{9}$/
8
+
9
+ # 2. Checksum
10
+ ```
11
+
12
+ #### Usage
13
+
14
+ ```ruby
15
+ class User < ActiveRecord::Base
16
+
17
+ validates :input_0, cusip: true
18
+
19
+ end
20
+ ```
data/docs/EMAIL.md ADDED
@@ -0,0 +1,26 @@
1
+ # Email
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
8
+ ```
9
+
10
+ #### Options
11
+
12
+ Option | Type | Available | Default
13
+ --- | --- | --- | ---
14
+ domain | array, string, symbol | |
15
+
16
+ #### Usage
17
+
18
+ ```ruby
19
+ class User < ActiveRecord::Base
20
+
21
+ validates :input_0, email: true
22
+ validates :input_1, email: { domain: 'com' }
23
+ validates :input_2, email: { domain: %w[com org] }
24
+
25
+ end
26
+ ```
@@ -0,0 +1,26 @@
1
+ # File content type
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Check
7
+ ```
8
+
9
+ #### Options
10
+
11
+ Option | Type | Available | Default
12
+ --- | --- | --- | ---
13
+ include | array, regexp, string, symbol | |
14
+ exclude | array, regexp, string, symbol | |
15
+
16
+ #### Usage
17
+
18
+ ```ruby
19
+ class User < ActiveRecord::Base
20
+
21
+ validates :input_0, file_content_type: { include: 'text/csv' }
22
+ validates :input_1, file_content_type: { exclude: %w[image/png text/plain] }
23
+ validates :input_2, file_content_type: { include: /^text\/.*/, exclude: 'text/csv' }
24
+
25
+ end
26
+ ```
@@ -0,0 +1,25 @@
1
+ # File extension
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Check
7
+ ```
8
+
9
+ #### Options
10
+
11
+ Option | Type | Available | Default
12
+ --- | --- | --- | ---
13
+ include | array, string, symbol | |
14
+ exclude | array, string, symbol | |
15
+
16
+ #### Usage
17
+
18
+ ```ruby
19
+ class User < ActiveRecord::Base
20
+
21
+ validates :input_0, file_extension: { include: 'csv' }
22
+ validates :input_1, file_extension: { exclude: [:png, 'text'] }
23
+
24
+ end
25
+ ```
data/docs/FILE_SIZE.md ADDED
@@ -0,0 +1,38 @@
1
+ # File size
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Check
7
+ :in => '==='
8
+ :less_than => '<'
9
+ :less_than_or_equal_to => '<='
10
+ :greater_than => '>'
11
+ :greater_than_or_equal_to => '>='
12
+ :equal_to => '=='
13
+ :not_equal_to => '!='
14
+ ```
15
+
16
+ #### Options
17
+
18
+ Option | Type | Available | Default
19
+ --- | --- | --- | ---
20
+ in | range | |
21
+ less_than | numeric | |
22
+ less_than_or_equal_to | numeric | |
23
+ greater_than | numeric | |
24
+ greater_than_or_equal_to | numeric | |
25
+ equal_to | numeric | |
26
+ not_equal_to | numeric | |
27
+
28
+ #### Usage
29
+
30
+ ```ruby
31
+ class User < ActiveRecord::Base
32
+
33
+ validates :input_0, file_size: { less_than: 100 }
34
+ validates :input_1, file_size: { greater_than_or_equal_to: 75, less_than: 100 }
35
+ validates :input_0, file_size: { in: (50..100) }
36
+
37
+ end
38
+ ```
data/docs/HEX.md ADDED
@@ -0,0 +1,18 @@
1
+ # HEX
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, hex: true
16
+
17
+ end
18
+ ```
data/docs/IMEI.md ADDED
@@ -0,0 +1,20 @@
1
+ # IMEI
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /\A[\d\.\:\-\s]+\z/i
8
+
9
+ # 2. Checksum
10
+ ```
11
+
12
+ #### Usage
13
+
14
+ ```ruby
15
+ class User < ActiveRecord::Base
16
+
17
+ validates :input_0, imei: true
18
+
19
+ end
20
+ ```
@@ -0,0 +1,26 @@
1
+ # IP address
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ :ipv4 => Resolv::IPv4::Regex
8
+ :ipv6 => Resolv::IPv6::Regex
9
+ ```
10
+
11
+ #### Options
12
+
13
+ Option | Type | Available | Default
14
+ --- | --- | --- | ---
15
+ protocol | symbol | any, ipv4, ipv6 | any
16
+
17
+ #### Usage
18
+
19
+ ```ruby
20
+ class User < ActiveRecord::Base
21
+
22
+ validates :input_0, ip_address: true
23
+ validates :input_1, ip_address: { protocol: :ipv4 }
24
+
25
+ end
26
+ ```
data/docs/ISBN.md ADDED
@@ -0,0 +1,18 @@
1
+ # ISBN
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Length
7
+ # 2. Pattern
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, isbn: true
16
+
17
+ end
18
+ ```
data/docs/ISIN.md ADDED
@@ -0,0 +1,20 @@
1
+ # ISIN
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^((AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW{2})([A-Z0-9]{9}))(\d{1})$/
8
+
9
+ # 2. Checksum
10
+ ```
11
+
12
+ #### Usage
13
+
14
+ ```ruby
15
+ class User < ActiveRecord::Base
16
+
17
+ validates :input_0, isin: true
18
+
19
+ end
20
+ ```
@@ -0,0 +1,21 @@
1
+ # MAC address
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ '2/5/2' => /^([\h]{2}[-|\.:|\s]){5}[\h]{2}?$/i
8
+ '4/2/4' => /^([\h]{4}[-|\.:|\s]){2}[\h]{4}?$/i
9
+ '6/6' => /^([\h]{6}[-|\.:|\s])[\h]{6}?$/i
10
+ '12' => /^[\h]{12}?$/i
11
+ ```
12
+
13
+ #### Usage
14
+
15
+ ```ruby
16
+ class User < ActiveRecord::Base
17
+
18
+ validates :input_0, mac_address: true
19
+
20
+ end
21
+ ```
data/docs/NAME.md ADDED
@@ -0,0 +1,18 @@
1
+ # Name
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^([A-Za-z'"-]+\s+){1,4}[A-Za-z'"-]*\z/
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, name: true
16
+
17
+ end
18
+ ```
data/docs/PASSWORD.md ADDED
@@ -0,0 +1,26 @@
1
+ # Password
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ :strong => /\A(?=.{4,255})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[[:^alnum:]])/x
8
+ :weak => /^[A-Za-z0-9.,<>:;!@#$%^&*?_~-]{1,255}$/
9
+ ```
10
+
11
+ #### Options
12
+
13
+ Option | Type | Available | Default
14
+ --- | --- | --- | ---
15
+ strength | symbol | strong, weak | weak
16
+
17
+ #### Usage
18
+
19
+ ```ruby
20
+ class User < ActiveRecord::Base
21
+
22
+ validates :input_0, password: true
23
+ validates :input_1, password: { strength: :strong }
24
+
25
+ end
26
+ ```
@@ -0,0 +1,18 @@
1
+ # Phone number
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^[0-9+\(\)#\.\s\/ext-]+$/
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, phone_number: true
16
+
17
+ end
18
+ ```
data/docs/SEDOL.md ADDED
@@ -0,0 +1,20 @@
1
+ # SEDOL
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^([A-Z0-9]{6})(\d{1})$/
8
+
9
+ # 2. Checksum
10
+ ```
11
+
12
+ #### Usage
13
+
14
+ ```ruby
15
+ class User < ActiveRecord::Base
16
+
17
+ validates :input_0, sedol: true
18
+
19
+ end
20
+ ```
data/docs/SLUG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Slug
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^[A-Za-z0-9_-]+$/i
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, slug: true
16
+
17
+ end
18
+ ```
data/docs/SSN.md ADDED
@@ -0,0 +1,18 @@
1
+ # SSN
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^\A([\d]{3}\-[\d]{2}\-[\d]{4}|[\d]{9})\Z$/
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, ssn: true
16
+
17
+ end
18
+ ```
data/docs/TIME_ZONE.md ADDED
@@ -0,0 +1,17 @@
1
+ # Time Zone
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ ```
8
+
9
+ #### Usage
10
+
11
+ ```ruby
12
+ class User < ActiveRecord::Base
13
+
14
+ validates :input_0, time_zone: true
15
+
16
+ end
17
+ ```
data/docs/TYPE.md ADDED
@@ -0,0 +1,28 @@
1
+ # Type
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Check
7
+ ```
8
+
9
+ #### Options
10
+
11
+ Option | Type | Available | Default
12
+ --- | --- | --- | ---
13
+ is | class | |
14
+ is_not | class | |
15
+
16
+ #### Usage
17
+
18
+ ```ruby
19
+ class User < ActiveRecord::Base
20
+
21
+ validates :input_0, type: { is: Array }
22
+ validates :input_1, type: { is: Boolean } #=> Checks both TrueClass and FalseClass
23
+ validates :input_2, type: { is: [Array, Hash] }
24
+ validates :input_3, type: { is_not: CustomKlass } #=> Any Class based objects
25
+ validates :input_4, type: { is_not: Integer }
26
+
27
+ end
28
+ ```
data/docs/URL.md ADDED
@@ -0,0 +1,28 @@
1
+ # URL
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ ```
8
+
9
+ #### Options
10
+
11
+ Option | Type | Available | Default
12
+ --- | --- | --- | ---
13
+ domain | array, string, symbol | |
14
+ root_only | boolean | true, false | false
15
+ scheme | array, string, symbol | |
16
+
17
+ #### Usage
18
+
19
+ ```ruby
20
+ class User < ActiveRecord::Base
21
+
22
+ validates :input_0, url: true
23
+ validates :input_1, url: { domain: [:com, 'org'] }
24
+ validates :input_2, url: { scheme: :https }
25
+ validates :input_3, url: { root_only: true }
26
+
27
+ end
28
+ ```
data/docs/USERNAME.md ADDED
@@ -0,0 +1,18 @@
1
+ # Username
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ /^[a-z0-9_-]{1,255}$/
8
+ ```
9
+
10
+ #### Usage
11
+
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+
15
+ validates :input_0, username: true
16
+
17
+ end
18
+ ```
data/docs/UUID.md ADDED
@@ -0,0 +1,28 @@
1
+ # UUID
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Pattern
7
+ :any => /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
8
+ 3 => /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i
9
+ 4 => /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
10
+ 5 => /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
11
+ ```
12
+
13
+ #### Options
14
+
15
+ Option | Type | Available | Default
16
+ --- | --- | --- | ---
17
+ version | symbol, integer | any, 3, 4, 5 | any
18
+
19
+ #### Usage
20
+
21
+ ```ruby
22
+ class User < ActiveRecord::Base
23
+
24
+ validates :input_0, uuid: true
25
+ validates :input_1, uuid: { version: 3 }
26
+
27
+ end
28
+ ```
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AlphaNumericValidator < AlphaValidator
4
+
5
+ private
6
+
7
+ def regexp
8
+ /^[#{CASES[kase]}0-9#{' ' if options[:allow_space]}]+$/
9
+ end
10
+
11
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AlphaValidator < BaseValidator
4
+
5
+ CASES ||= {
6
+ lower: 'a-z',
7
+ upper: 'A-Z',
8
+ any: 'A-Za-z'
9
+ }.freeze
10
+
11
+ def validate_each(record, attribute, value)
12
+ assert_valid_case!
13
+ super
14
+ end
15
+
16
+ private
17
+
18
+ def assert_valid_case!
19
+ assert_valid_option!(:case, CASES.keys, option: kase)
20
+ end
21
+
22
+ def kase
23
+ options[:case] || :any
24
+ end
25
+
26
+ def regexp
27
+ /^[#{CASES[kase]}#{' ' if options[:allow_space]}]+$/
28
+ end
29
+
30
+ def valid_regexp?
31
+ value.to_s =~ regexp
32
+ end
33
+
34
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Base64Validator < BaseValidator
4
+
5
+ # rubocop:disable Metrics/LineLength
6
+ REGEXP ||= /^(?:[A-Za-z0-9+$]{4})*(?:[A-Za-z0-9+$]{2}==|[A-Za-z0-9+$]{3}=|[A-Za-z0-9+$]{4})$/.freeze
7
+ # rubocop:enable Metrics/LineLength
8
+
9
+ end