README.md in flash_validators-1.1.0 vs README.md in flash_validators-3.0.0
- old
+ new
@@ -5,11 +5,11 @@
[![Coverage Status](https://coveralls.io/repos/drexed/flash_validators/badge.png)](https://coveralls.io/r/drexed/flash_validators)
[![Code Climate](https://codeclimate.com/github/drexed/flash_validators.png)](https://codeclimate.com/github/drexed/flash_validators)
Flash Validators is a collection of custom validators that are often required in Rails applications plus shoulda-style RSpec matchers to test the validation rules.
-Currently supported validators: alpha, alpha-numeric, boolean, credit card, currency, email, equality, hex, IMEI, IP, ISBN, latitude, longitude, mac address, name, password, phone, slug, ssn, url, and username.
+Currently supported validators: alpha, alpha-numeric, Base64, boolean, credit card, currency, CUSIP, email, equality, GTIN, hex, IMEI, IP, ISBN, ISIN, latitude, longitude, MAC address, name, password, phone, SEDOL, slug, SSN, url, username, and UUID.
Highly recommended validators:
* **DateTime:** Validates Timeliness - https://github.com/adzap/validates_timeliness
* **Existence:** Validates Existence - https://github.com/perfectline/validates_existence
* **Group:** Group Validations - https://github.com/adzap/grouped_validations
@@ -56,22 +56,22 @@
attr_accessor :title, :name
validates :title, alpha: true
end
```
-Options: :strict, :lowercase, :uppercase
+Options: :strict, case: [:lower, :upper]
```ruby
validates :title, alpha: { strict: true }
-validates :title, alpha: { lowercase: true }
-validates :title, alpha: { uppsercase: true }
+validates :title, alpha: { case: :lower }
+validates :title, alpha: { case: :upper, strict: true }
```
RSpec matcher is also available for your convenience:
```ruby
-describe Product do
+describe Book do
it { should ensure_valid_alpha_format_of(:title) }
it { should_not ensure_valid_alpha_format_of(:name) }
end
```
@@ -100,31 +100,68 @@
attr_accessor :title, :name
validates :title, alpha_numeric: true
end
```
+Options: :strict
Strict: requires not including spaces
```ruby
validates :title, alpha_numeric: { strict: true }
```
RSpec matcher is also available for your convenience:
```ruby
-describe Product do
+describe Book do
it { should ensure_valid_alpha_numeric_format_of(:title) }
it { should_not ensure_valid_alpha_numeric_format_of(:name) }
end
```
+### Base64Validator
+
+**Ex:** YW55IGNhcm5hbCBwbGVhcw==
+
+**Rules:**
+ * Characters: 0-1 A-Z =
+
+With an ActiveRecord model:
+
+```ruby
+class Code < ActiveRecord::Base
+ attr_accessor :code, :name
+ validates :code, base64: true
+end
+```
+
+Or any ruby class:
+
+```ruby
+class Code
+ include ActiveModel::Validations
+ attr_accessor :code, :name
+ validates :code, base64: true
+end
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe Code do
+ it { should ensure_valid_base64_format_of(:code) }
+ it { should_not ensure_valid_base64_format_of(:name) }
+end
+```
+
### BooleanValidator
**Ex:** true or false or 1 or 0
**Rules:**
- * Characters: 0-1 true or false
+ * Characters: 0-1
+ * Equality: true or false
With an ActiveRecord model:
```ruby
class User < ActiveRecord::Base
@@ -144,23 +181,24 @@
```
RSpec matcher is also available for your convenience:
```ruby
-describe Product do
+describe User do
it { should ensure_valid_boolean_format_of(:active) }
it { should_not ensure_valid_boolean_format_of(:name) }
end
```
+
### CreditCardValidator
**Ex:** 370000000000002
**Rules:**
- * Characters: 0-9
+ * Characters: 0-9 .-
* Must include: 0-9
- * Range for card digits: 15-16
+ * Range for card digits: 12-19
With an ActiveRecord model:
```ruby
class Invoice < ActiveRecord::Base
@@ -177,19 +215,17 @@
attr_accessor :cc_number, :name
validates :cc_number, credit_card: true
end
```
-Options: :american_express, :diners_club, :discover, :jbc, :master_card, :visa
+Options: :strict, card: [:american_express (:amex), :diners_club, :discover, :jbc, :laser, :maestro, :mastercard, :solo, :unionpay, :visa]
+Strict: requires not including spaces
```ruby
-validates :cc_number, currency: { american_express: true }
-validates :cc_number, currency: { diners_club: true }
-validates :cc_number, currency: { discover: true }
-validates :cc_number, currency: { jbc: true }
-validates :cc_number, currency: { master_card: true }
-validates :cc_number, currency: { visa: true }
+validates :cc_number, credit_card: { card: :visa }
+validates :cc_number, credit_card: { strict: true }
+validates :cc_number, credit_card: { card: :discover, strict: true }
```
RSpec matcher is also available for your convenience:
```ruby
@@ -225,10 +261,11 @@
attr_accessor :price, :name
validates :price, currency: true
end
```
+Options: :strict
Strict: requires leading number and exactly two decimals, 1.45
```ruby
validates :price, currency: { strict: true }
```
@@ -240,10 +277,46 @@
it { should ensure_valid_currency_format_of(:price) }
it { should_not ensure_valid_currency_format_of(:name) }
end
```
+### CusipValidator
+
+**Ex:** 125509BG3
+
+**Rules:**
+ * Characters: 0-1 A-Z
+ * Length: 1-9
+
+With an ActiveRecord model:
+
+```ruby
+class Bank < ActiveRecord::Base
+ attr_accessor :code, :name
+ validates :code, cusip: true
+end
+```
+
+Or any ruby class:
+
+```ruby
+class Bank
+ include ActiveModel::Validations
+ attr_accessor :code, :name
+ validates :code, cusip: true
+end
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe Bank do
+ it { should ensure_valid_cusip_format_of(:code) }
+ it { should_not ensure_cusip_base64_format_of(:name) }
+end
+```
+
### EmailValidator
**Ex:** user@example.com or user+123@example-site.com
**Rules:**
@@ -269,11 +342,11 @@
attr_accessor :email, :name
validates :email, email: true
end
```
-You can specify domains to which the email domain should belong in one of the folowing ways:
+Options: :domains
```ruby
validates :email, email: { domains: 'com' }
validates :email, email: { domains: :com }
validates :email, email: { domains: [:com, 'edu'] }
@@ -328,18 +401,63 @@
it { should ensure_equality_of(:bid).to(:price) }
it { should_not ensure_equality_of(:bid).to(:product) }
end
```
+### GtinValidator
+
+**Ex:** 73513537 or 4 006381 33393 1
+
+**Rules:**
+* Length: 8, 12, 13, or 14
+* Characters: 0-9
+
+With an ActiveRecord model:
+
+```ruby
+class Trade < ActiveRecord::Base
+ attr_accessor :code, :name
+ validates :code, gtin: true
+end
+```
+
+Or any ruby class:
+
+```ruby
+class Trade
+ include ActiveModel::Validations
+ attr_accessor :code, :name
+ validates :code, gtin: true
+end
+```
+
+Options: :strict, format: [:ean_8, :gtin_8, :ucc_8, :gtin_12, :upc, :upc_a, :ean, :ean_13, :gtin_13, :ucc_13, :gtin_14, :ucc_14]
+Strict: requires not including spaces
+
+```ruby
+validates :code, gtin: { format: :ean_8 }
+validates :code, gtin: { strict: true }
+validates :code, gtin: { format: :ucc_13, strict: true }
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe Trade do
+ it { should ensure_valid_gtin_format_of(:code) }
+ it { should_not ensure_valid_gtin_format_of(:name) }
+end
+```
+
### HexValidator
-**Ex:** #a9a9a9 or #999 or aaaaaa
+**Ex:** #a9a9a9 or #999 or aaaaaa or AAA
**Rules:**
* Prefix (non-mandatory): #
* Length: 3 or 6
-* Characters: a-f 0-9
+* Characters: A-F a-f 0-9
With an ActiveRecord model:
```ruby
class Profile < ActiveRecord::Base
@@ -473,10 +591,47 @@
it { should ensure_valid_isbn_format_of(:isbn) }
it { should_not ensure_valid_isbn_format_of(:name) }
end
```
+### IsinValidator
+
+**Ex:** US0378331005 or AU0000XVGZA3
+
+**Rules:**
+* Length: 12
+* Characters: 0-9 A-Z
+* Start: valid country code
+
+With an ActiveRecord model:
+
+```ruby
+class Trade < ActiveRecord::Base
+ attr_accessor :isin, :name
+ validates :isin, isin: true
+end
+```
+
+Or any ruby class:
+
+```ruby
+class User
+ include ActiveModel::Validations
+ attr_accessor :isin, :name
+ validates :isin, isin: true
+end
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe User do
+ it { should ensure_valid_isin_format_of(:isin) }
+ it { should_not ensure_valid_isin_format_of(:name) }
+end
+```
+
### LatitudeValidator
**Ex:** 78.213 or -34.985
**Rules:**
@@ -649,11 +804,11 @@
include ActiveModel::Validations
attr_accessor :password, :name
validates :password, password: true
end
```
-
+Options: :strict
Strict: requires length between 6 and 18, one number, lowercase, upcase letter
```ruby
validates :password, password: { strict: true }
```
@@ -700,10 +855,45 @@
it { should ensure_valid_phone_format_of(:phone) }
it { should_not ensure_valid_phone_format_of(:name) }
end
```
+### SedolValidator
+
+**Ex:** B0WNLY7
+
+**Rules:**
+* Characters: A-Z 0-9
+
+With an ActiveRecord model:
+
+```ruby
+class Trade < ActiveRecord::Base
+ attr_accessor :sedol, :name
+ validates :sedol, sedol: true
+end
+```
+
+Or any ruby class:
+
+```ruby
+class Trade
+ include ActiveModel::Validations
+ attr_accessor :sedol, :name
+ validates :sedol, sedol: true
+end
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe Trade do
+ it { should ensure_valid_sedol_format_of(:sedol) }
+ it { should_not ensure_valid_sedol_format_of(:name) }
+end
+```
+
### SlugValidator
**Ex:** slug1234 or slug-1234
**Rules:**
@@ -798,31 +988,23 @@
attr_accessor :url, :name
validates :url, url: true
end
```
-You can specify domains to which the URL domain should belong in one of the folowing ways:
+Options: :domains, :root, :scheme
```ruby
+validates :url, url: { scheme: :http }
+validates :url, url: { scheme: [:http, 'https'] }
+validates :url, url: { scheme: :http, root: true, domains: :com }
+validates :url, url: { root: true }
+validates :url, url: { root: true, domains: :com }
validates :url, url: { domains: 'com' }
validates :url, url: { domains: :com }
validates :url, url: { domains: [:com, 'edu'] }
```
-You can specify if the URL should the site root:
-
-```ruby
-validates :url, url: { root: true }
-```
-
-You can specify the URL scheme:
-
-```ruby
-validates :url, url: { scheme: :http }
-validates :url, url: { scheme: [:http, 'https'] }
-```
-
RSpec matcher is also available for your convenience:
```ruby
describe User do
it { should ensure_valid_url_format_of(:url) }
@@ -861,9 +1043,50 @@
```ruby
describe User do
it { should ensure_valid_username_format_of(:username) }
it { should_not ensure_valid_username_format_of(:name) }
+end
+```
+
+### UuidValidator
+
+**Ex:** 886313e1-3b8a-5372-9b90-0c9aee199e5d
+
+**Rules:**
+* Characters: A-Z a-z 0-9 -
+
+With an ActiveRecord model:
+
+```ruby
+class User < ActiveRecord::Base
+ attr_accessor :uuid, :name
+ validates :uuid, uuid: true
+end
+```
+
+Or any ruby class:
+
+```ruby
+class User
+ include ActiveModel::Validations
+ attr_accessor :uuid, :name
+ validates :uuid, username: true
+end
+```
+
+Options: :version
+
+```ruby
+validates :uuid, uuid: { version: 3 }
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe User do
+ it { should ensure_valid_uuid_format_of(:uuid) }
+ it { should_not ensure_valid_uuid_format_of(:name) }
end
```
## Contributing