README.md in active_validation-1.0.0 vs README.md in active_validation-1.1.0
- old
+ new
@@ -4,12 +4,10 @@
[![Build Status](https://travis-ci.org/drexed/active_validation.svg?branch=master)](https://travis-ci.org/drexed/active_validation)
[![Coverage Status](https://coveralls.io/repos/drexed/active_validation/badge.png)](https://coveralls.io/r/drexed/active_validation)
ActiveValidation 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, 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
* **Overlap:** Validates Overlap - https://github.com/robinbortlik/validates_overlap
@@ -26,14 +24,40 @@
Or install it yourself as:
$ gem install active_validation
-## Usage
+## Table of Contents
-### AlphaValidator
+* [Alpha](#alphavalidator)
+* [AlphaNumeric](#alphanumericvalidator)
+* [Base64](#base64validator)
+* [Boolean](#booleanvalidator)
+* [Coordinates](#coordinatesvalidator)
+* [Credit Card](#creditcardvalidator)
+* [Currency](#currencyvalidator)
+* [CUSIP](#cusipvalidator)
+* [Email](#emailvalidator)
+* [Equality](#equalityvalidator)
+* [Hex](#hexvalidator)
+* [IMEI](#imeivalidator)
+* [IP](#ipvalidator)
+* [ISBN](#isbnvalidator)
+* [ISIN](#isinvalidator)
+* [MAC Address](#macaddressvalidator)
+* [Name](#namevalidator)
+* [Password](#passwordvalidator)
+* [Phone](#phonevalidator)
+* [SEDOL](#sedolvalidator)
+* [Slug](#slugvalidator)
+* [SSN](#ssnvalidator)
+* [URL](#urlvalidator)
+* [Username](#usernamevalidator)
+* [UUID](#uuidvalidator)
+## AlphaValidator
+
**Ex:** Example or Example Title
**Rules:**
* Characters: A-Z a-z
* Must include: A-Z a-z
@@ -72,11 +96,11 @@
it { should ensure_valid_alpha_format_of(:title) }
it { should_not ensure_valid_alpha_format_of(:name) }
end
```
-### AlphaNumericValidator
+## AlphaNumericValidator
**Ex:** Example1 or Example Title 1
**Rules:**
* Characters: A-Z a-z 0-9
@@ -115,11 +139,11 @@
it { should ensure_valid_alpha_numeric_format_of(:title) }
it { should_not ensure_valid_alpha_numeric_format_of(:name) }
end
```
-### Base64Validator
+## Base64Validator
**Ex:** YW55IGNhcm5hbCBwbGVhcw==
**Rules:**
* Characters: 0-1 A-Z =
@@ -150,11 +174,11 @@
it { should ensure_valid_base64_format_of(:code) }
it { should_not ensure_valid_base64_format_of(:name) }
end
```
-### BooleanValidator
+## BooleanValidator
**Ex:** true or false or 1 or 0
**Rules:**
* Characters: 0-1
@@ -186,12 +210,60 @@
it { should ensure_valid_boolean_format_of(:active) }
it { should_not ensure_valid_boolean_format_of(:name) }
end
```
-### CreditCardValidator
+## CoordinateValidator
+**Ex:** 178.213 or -34.985
+
+**Rules:**
+* Range: latitude (90 to -90), longitude (180 to -180)
+* Characters: 0-9
+
+With an ActiveRecord model:
+
+```ruby
+# :coor => [78.47, -169.92]
+# :lat => 91.23
+# :lon => 123.85
+
+class Location < ActiveRecord::Base
+ attr_accessor :coor, :lat, :lon, :name
+ validates :coor, coordinate: true
+ validates :lat, coordinate: { boundary: :latitude }
+ validates :lon, coordinate: { boundary: :longitude }
+end
+```
+
+Or any ruby class:
+
+```ruby
+# :coor => [78.47, -169.92]
+# :lat => 91.23
+# :lon => 123.85
+
+class Location
+ include ActiveModel::Validations
+ attr_accessor :coor, :lat, :lon, :name
+ validates :coor, coordinate: true
+ validates :lat, coordinate: { boundary: :latitude }
+ validates :lon, coordinate: { boundary: :longitude }
+end
+```
+
+RSpec matcher is also available for your convenience:
+
+```ruby
+describe Location do
+ it { should ensure_valid_coordinate_format_of(:coor) }
+ it { should_not ensure_valid_coordinate_format_of(:name) }
+end
+```
+
+## CreditCardValidator
+
**Ex:** 370000000000002
**Rules:**
* Characters: 0-9 .-
* Must include: 0-9
@@ -232,11 +304,11 @@
it { should ensure_valid_credit_card_format_of(:cc_number) }
it { should_not ensure_valid_credit_card_format_of(:name) }
end
```
-### CurrencyValidator
+## CurrencyValidator
**Ex:** 123.00 or .1
**Rules:**
* Characters: 0-9 .
@@ -276,11 +348,11 @@
it { should ensure_valid_currency_format_of(:price) }
it { should_not ensure_valid_currency_format_of(:name) }
end
```
-### CusipValidator
+## CusipValidator
**Ex:** 125509BG3
**Rules:**
* Characters: 0-1 A-Z
@@ -312,11 +384,11 @@
it { should ensure_valid_cusip_format_of(:code) }
it { should_not ensure_cusip_base64_format_of(:name) }
end
```
-### EmailValidator
+## EmailValidator
**Ex:** user@example.com or user+123@example-site.com
**Rules:**
* Characters in username: a-z 0-9 -_+.
@@ -358,11 +430,11 @@
it { should ensure_valid_email_format_of(:email) }
it { should_not ensure_valid_email_format_of(:name) }
end
```
-### EqualityValidator
+## EqualityValidator
**Operators:**
* Less than: x < y
* Less than or equal to: x <= y
* Greater than: x > y
@@ -400,57 +472,12 @@
it { should ensure_equality_of(:bid).to(:price) }
it { should_not ensure_equality_of(:bid).to(:product) }
end
```
-### GtinValidator
+## HexValidator
-**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 or AAA
**Rules:**
* Prefix (non-mandatory): #
* Length: 3 or 6
@@ -482,11 +509,11 @@
it { should ensure_valid_hex_format_of(:color) }
it { should_not ensure_valid_hex_format_of(:trim) }
end
```
-### ImeiValidator
+## ImeiValidator
**Ex:** 356843052637512 or 35-6843052-637512 or 35.6843052.637512
**Rules:**
* Length: min 14
@@ -518,11 +545,11 @@
it { should ensure_valid_imei_format_of(:imei) }
it { should_not ensure_valid_imei_format_of(:name) }
end
```
-### IpValidator
+## IpValidator
**Ex:** 0.0.0.0 or 127.0.0.1 or 167.39.240.31
**Rules:**
* Length: min 7
@@ -554,11 +581,11 @@
it { should ensure_valid_ip_format_of(:ip) }
it { should_not ensure_valid_ip_format_of(:name) }
end
```
-### IsbnValidator
+## IsbnValidator
**Ex:** 9519854894 or 0-9722051-1-x or 978 159059 9938
**Rules:**
* Length: 10 or 13
@@ -590,11 +617,11 @@
it { should ensure_valid_isbn_format_of(:isbn) }
it { should_not ensure_valid_isbn_format_of(:name) }
end
```
-### IsinValidator
+## IsinValidator
**Ex:** US0378331005 or AU0000XVGZA3
**Rules:**
* Length: 12
@@ -627,84 +654,12 @@
it { should ensure_valid_isin_format_of(:isin) }
it { should_not ensure_valid_isin_format_of(:name) }
end
```
-### LatitudeValidator
+## MacAddressValidator
-**Ex:** 78.213 or -34.985
-
-**Rules:**
-* Range: 90 to -90
-* Characters: 0-9
-
-With an ActiveRecord model:
-
-```ruby
-class Location < ActiveRecord::Base
- attr_accessor :lat, :name
- validates :lat, latitude: true
-end
-```
-
-Or any ruby class:
-
-```ruby
-class Location
- include ActiveModel::Validations
- attr_accessor :lat, :name
- validates :lat, latitude: true
-end
-```
-
-RSpec matcher is also available for your convenience:
-
-```ruby
-describe Location do
- it { should ensure_valid_latitude_format_of(:lat) }
- it { should_not ensure_valid_latitude_format_of(:name) }
-end
-```
-
-### LongitudeValidator
-
-**Ex:** 165.371 or -56.152
-
-**Rules:**
-* Range: 180 to -180
-* Characters: 0-9
-
-With an ActiveRecord model:
-
-```ruby
-class Location < ActiveRecord::Base
- attr_accessor :lon, :name
- validates :lon, longitude: true
-end
-```
-
-Or any ruby class:
-
-```ruby
-class Location
- include ActiveModel::Validations
- attr_accessor :lon, :name
- validates :lon, longitude: true
-end
-```
-
-RSpec matcher is also available for your convenience:
-
-```ruby
-describe Location do
- it { should ensure_valid_longitude_format_of(:lon) }
- it { should_not ensure_valid_longitude_format_of(:name) }
-end
-```
-
-### MacAddressValidator
-
**Ex:**
'08:00:2b:01:02:03'
'08-00-2b-01-02-03'
'08002b:010203'
'08002b-010203'
@@ -740,11 +695,11 @@
it { should ensure_valid_mac_address_format_of }
it { should_not ensure_valid_mac_address_format_of(:name) }
end
```
-### NameValidator
+## NameValidator
**Ex:** James Brown or Billy Bob Thorton Jr
**Rules:**
* Range: 2 - 5 names
@@ -777,11 +732,11 @@
it { should ensure_valid_name_format_of(:name) }
it { should_not ensure_valid_name_format_of(:email) }
end
```
-### PasswordValidator
+## PasswordValidator
**Ex:** password or password123 or pa!!word
**Rules:**
* Range: 6-18
@@ -819,11 +774,11 @@
it { should ensure_valid_password_format_of(:password) }
it { should_not ensure_valid_password_format_of(:name) }
end
```
-### PhoneValidator
+## PhoneValidator
**Ex:** 555 333 4444 or (555) 123-4567 or +1 (555) 123 4567 ext-890
**Rules:**
* Characters: a-z 0-9 -()+
@@ -854,11 +809,11 @@
it { should ensure_valid_phone_format_of(:phone) }
it { should_not ensure_valid_phone_format_of(:name) }
end
```
-### SedolValidator
+## SedolValidator
**Ex:** B0WNLY7
**Rules:**
* Characters: A-Z 0-9
@@ -889,11 +844,11 @@
it { should ensure_valid_sedol_format_of(:sedol) }
it { should_not ensure_valid_sedol_format_of(:name) }
end
```
-### SlugValidator
+## SlugValidator
**Ex:** slug1234 or slug-1234
**Rules:**
* Characters: a-z 0-9 -
@@ -924,11 +879,11 @@
it { should ensure_valid_slug_format_of(:slug) }
it { should_not ensure_valid_slug_format_of(:name) }
end
```
-### SsnValidator
+## SsnValidator
**Ex:** 333-22-4444 or 333224444
**Rules:**
* Characters: 0-9 -
@@ -959,11 +914,11 @@
it { should ensure_valid_ssn_format_of(:ssn) }
it { should_not ensure_valid_ssn_format_of(:name) }
end
```
-### UrlValidator
+## UrlValidator
**Ex:** example.com or http://www.example.com
**Rules:**
* Characters in root: a-z 0-9 -.//:
@@ -1009,11 +964,11 @@
it { should ensure_valid_url_format_of(:url) }
it { should_not ensure_valid_url_format_of(:name) }
end
```
-### UsernameValidator
+## UsernameValidator
**Ex:** username123 or username
**Rules:**
* Range: 2-16
@@ -1045,10 +1000,10 @@
it { should ensure_valid_username_format_of(:username) }
it { should_not ensure_valid_username_format_of(:name) }
end
```
-### UuidValidator
+## UuidValidator
**Ex:** 886313e1-3b8a-5372-9b90-0c9aee199e5d
**Rules:**
* Characters: A-Z a-z 0-9 -