From d8cc2d293afe39e92e3409e47fc59d90904ebd01 Mon Sep 17 00:00:00 2001 From: Nicolas Talle Date: Sun, 28 Feb 2021 19:52:41 +0100 Subject: [PATCH] v1.4.0 --- README.md | 2 +- docs/Check.html | 48 ++++++- docs/Check/Checkable.html | 21 ++- docs/Check/CheckableStatic.html | 29 +++- docs/Check/Checker.html | 13 +- docs/Check/Errors.html | 13 +- docs/Check/Validation.html | 33 ++++- docs/Check/ValidationError.html | 17 ++- docs/Valid.html | 13 +- docs/Validator.html | 226 +++++++++++++++++++++++++++++++- docs/Validator/Error.html | 13 +- docs/index.html | 41 ++++-- docs/index.json | 2 +- docs/search-index.js | 2 +- docs/toplevel.html | 10 +- shard.yml | 4 +- 16 files changed, 434 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index a8c7624..74d1b46 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Also [validator/check](#check) (not exposed by default) provides: dependencies: validator: github: nicolab/crystal-validator - version: ~> 1.2.0 # Check the latest version! + version: ~> 1.4.0 # Check the latest version! ``` 2. Run `shards install` diff --git a/docs/Check.html b/docs/Check.html index 50f8435..22e4ce2 100644 --- a/docs/Check.html +++ b/docs/Check.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check - validator master-dev + Check - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -166,6 +166,20 @@

Defined in:

+ + + check.cr + + +
+ + + + checkable.cr + + +
+ @@ -276,6 +290,8 @@


+ [View source] +
@@ -302,6 +318,8 @@


+ [View source] +
@@ -369,6 +387,8 @@


+ [View source] +
@@ -394,17 +414,29 @@

property content : String property url : String? + private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool) + puts "after_check_content" + puts "Valid? #{v.valid?}" + content + end + Check.rules( content: { - required: "Content is required", # or `true` to use the default error message - check: { + required: "Content is required", # or `true` to use the default error message + before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) { + puts "before_check_content" + content + }, + after_check: :after_check_email, + check: { not_empty: {"Article content is required"}, between: {"The article content must be between 10 and 20 000 characters", 10, 20_000}, # ... }, clean: { - type: String, - to: :to_s, + type: String, + to: :to_s, + # Proc or method name (Symbol) format: ->(content : String) { content.strip }, message: "Wrong type", }, @@ -446,6 +478,8 @@


+ [View source] +
diff --git a/docs/Check/Checkable.html b/docs/Check/Checkable.html index b7219aa..ce99552 100644 --- a/docs/Check/Checkable.html +++ b/docs/Check/Checkable.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check::Checkable - validator master-dev + Check::Checkable - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -168,6 +168,13 @@

Defined in:

+ + + checkable.cr + + +
+ @@ -260,6 +267,8 @@


+ [View source] +
@@ -284,6 +293,8 @@


+ [View source] +
@@ -312,6 +323,8 @@


+ [View source] +
@@ -340,6 +353,8 @@


+ [View source] +
diff --git a/docs/Check/CheckableStatic.html b/docs/Check/CheckableStatic.html index 9929d37..3a7c068 100644 --- a/docs/Check/CheckableStatic.html +++ b/docs/Check/CheckableStatic.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check::CheckableStatic - validator master-dev + Check::CheckableStatic - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -168,6 +168,13 @@

Defined in:

+ + + checkable.cr + + +
+ @@ -294,6 +301,8 @@


+ [View source] +
@@ -319,6 +328,8 @@


+ [View source] +
@@ -348,6 +359,8 @@


+ [View source] +
@@ -377,6 +390,8 @@


+ [View source] +
@@ -401,6 +416,8 @@


+ [View source] +
@@ -420,6 +437,8 @@


+ [View source] +
@@ -439,6 +458,8 @@


+ [View source] +
@@ -458,6 +479,8 @@


+ [View source] +
diff --git a/docs/Check/Checker.html b/docs/Check/Checker.html index 98b07bb..3ae0f8b 100644 --- a/docs/Check/Checker.html +++ b/docs/Check/Checker.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check::Checker - validator master-dev + Check::Checker - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -181,6 +181,13 @@

Defined in:

+ + + checkable.cr + + +
+ diff --git a/docs/Check/Errors.html b/docs/Check/Errors.html index 614bf2f..5fb6979 100644 --- a/docs/Check/Errors.html +++ b/docs/Check/Errors.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check::Errors - validator master-dev + Check::Errors - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -180,6 +180,13 @@

Defined in:

+ + + check.cr + + +
+ diff --git a/docs/Check/Validation.html b/docs/Check/Validation.html index 09e0a32..6cb6a6b 100644 --- a/docs/Check/Validation.html +++ b/docs/Check/Validation.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check::Validation - validator master-dev + Check::Validation - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -277,6 +277,13 @@

Defined in:

+ + + check.cr + + +
+ @@ -440,6 +447,8 @@


+ [View source] +
@@ -465,6 +474,8 @@


+ [View source] +
@@ -504,6 +515,8 @@


+ [View source] +
@@ -531,6 +544,8 @@


+ [View source] +
@@ -579,6 +594,8 @@


+ [View source] +
@@ -627,6 +644,8 @@


+ [View source] +
@@ -659,6 +678,8 @@


+ [View source] +
@@ -681,6 +702,8 @@


+ [View source] +
@@ -700,6 +723,8 @@


+ [View source] +
@@ -723,6 +748,8 @@


+ [View source] +
diff --git a/docs/Check/ValidationError.html b/docs/Check/ValidationError.html index c831052..ee1d137 100644 --- a/docs/Check/ValidationError.html +++ b/docs/Check/ValidationError.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Check::ValidationError - validator master-dev + Check::ValidationError - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -169,6 +169,13 @@

Defined in:

+ + + check.cr + + +
+ @@ -273,6 +280,8 @@


+ [View source] +
@@ -306,6 +315,8 @@


+ [View source] +
diff --git a/docs/Valid.html b/docs/Valid.html index 2e56344..124cf49 100644 --- a/docs/Valid.html +++ b/docs/Valid.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Valid - validator master-dev + Valid - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -176,6 +176,13 @@

Defined in:

+ + + validator.cr + + +
+ diff --git a/docs/Validator.html b/docs/Validator.html index d6e759f..460286e 100644 --- a/docs/Validator.html +++ b/docs/Validator.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Validator - validator master-dev + Validator - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -267,6 +267,62 @@

Defined in:

+ + + validator.cr + + +
+ + + + validators/alpha_num.cr + + +
+ + + + validators/case_sensitive.cr + + +
+ + + + validators/comparisons.cr + + +
+ + + + validators/format.cr + + +
+ + + + validators/geo.cr + + +
+ + + + validators/presence.cr + + +
+ + + + validators/uri.cr + + +
+ @@ -917,6 +973,8 @@


+ [View source] +
@@ -938,6 +996,8 @@


+ [View source] +
@@ -961,6 +1021,8 @@


+ [View source] +
@@ -986,6 +1048,8 @@


+ [View source] +
@@ -1006,6 +1070,8 @@


+ [View source] +
@@ -1026,6 +1092,8 @@


+ [View source] +
@@ -1045,6 +1113,8 @@


+ [View source] +
@@ -1064,6 +1134,8 @@


+ [View source] +
@@ -1086,6 +1158,8 @@


+ [View source] +
@@ -1100,6 +1174,8 @@


+ [View source] +
@@ -1123,6 +1199,8 @@


+ [View source] +
@@ -1144,6 +1222,8 @@


+ [View source] +
@@ -1165,6 +1245,8 @@


+ [View source] +
@@ -1186,6 +1268,8 @@


+ [View source] +
@@ -1207,6 +1291,8 @@


+ [View source] +
@@ -1226,6 +1312,8 @@


+ [View source] +
@@ -1245,6 +1333,8 @@


+ [View source] +
@@ -1265,6 +1355,8 @@


+ [View source] +
@@ -1286,6 +1378,8 @@


+ [View source] +
@@ -1308,6 +1402,8 @@


+ [View source] +
@@ -1328,6 +1424,8 @@


+ [View source] +
@@ -1348,6 +1446,8 @@


+ [View source] +
@@ -1371,6 +1471,8 @@


+ [View source] +
@@ -1392,6 +1494,8 @@


+ [View source] +
@@ -1413,6 +1517,8 @@


+ [View source] +
@@ -1434,6 +1540,8 @@


+ [View source] +
@@ -1455,6 +1563,8 @@


+ [View source] +
@@ -1476,6 +1586,8 @@


+ [View source] +
@@ -1497,6 +1609,8 @@


+ [View source] +
@@ -1516,6 +1630,8 @@


+ [View source] +
@@ -1535,6 +1651,8 @@


+ [View source] +
@@ -1554,6 +1672,8 @@


+ [View source] +
@@ -1576,6 +1696,8 @@


+ [View source] +
@@ -1595,6 +1717,8 @@


+ [View source] +
@@ -1616,6 +1740,8 @@


+ [View source] +
@@ -1638,6 +1764,8 @@


+ [View source] +
@@ -1659,6 +1787,8 @@


+ [View source] +
@@ -1678,6 +1808,8 @@


+ [View source] +
@@ -1698,6 +1830,8 @@


+ [View source] +
@@ -1717,6 +1851,8 @@


+ [View source] +
@@ -1739,6 +1875,8 @@


+ [View source] +
@@ -1760,6 +1898,8 @@


+ [View source] +
@@ -1779,6 +1919,8 @@


+ [View source] +
@@ -1798,6 +1940,8 @@


+ [View source] +
@@ -1817,6 +1961,8 @@


+ [View source] +
@@ -1836,6 +1982,8 @@


+ [View source] +
@@ -1857,6 +2005,8 @@


+ [View source] +
@@ -1878,6 +2028,8 @@


+ [View source] +
@@ -1897,6 +2049,8 @@


+ [View source] +
@@ -1918,6 +2072,8 @@


+ [View source] +
@@ -1939,6 +2095,8 @@


+ [View source] +
@@ -1959,6 +2117,8 @@


+ [View source] +
@@ -1979,6 +2139,8 @@


+ [View source] +
@@ -2000,6 +2162,8 @@


+ [View source] +
@@ -2021,6 +2185,8 @@


+ [View source] +
@@ -2042,6 +2208,8 @@


+ [View source] +
@@ -2063,6 +2231,8 @@


+ [View source] +
@@ -2084,6 +2254,8 @@


+ [View source] +
@@ -2105,6 +2277,8 @@


+ [View source] +
@@ -2126,6 +2300,8 @@


+ [View source] +
@@ -2147,6 +2323,8 @@


+ [View source] +
@@ -2168,6 +2346,8 @@


+ [View source] +
@@ -2187,6 +2367,8 @@


+ [View source] +
@@ -2207,6 +2389,8 @@


+ [View source] +
@@ -2227,6 +2411,8 @@


+ [View source] +
@@ -2248,6 +2434,8 @@


+ [View source] +
@@ -2269,6 +2457,8 @@


+ [View source] +
@@ -2294,6 +2484,8 @@


+ [View source] +
@@ -2317,6 +2509,8 @@


+ [View source] +
@@ -2338,6 +2532,8 @@


+ [View source] +
@@ -2359,6 +2555,8 @@


+ [View source] +
@@ -2380,6 +2578,8 @@


+ [View source] +
@@ -2399,6 +2599,8 @@


+ [View source] +
@@ -2418,6 +2620,8 @@


+ [View source] +
@@ -2437,6 +2641,8 @@


+ [View source] +
@@ -2458,6 +2664,8 @@


+ [View source] +
@@ -2479,6 +2687,8 @@


+ [View source] +
@@ -2500,6 +2710,8 @@


+ [View source] +
@@ -2519,6 +2731,8 @@


+ [View source] +
@@ -2538,6 +2752,8 @@


+ [View source] +
@@ -2557,6 +2773,8 @@


+ [View source] +
@@ -2577,6 +2795,8 @@


+ [View source] +
diff --git a/docs/Validator/Error.html b/docs/Validator/Error.html index c439548..0a16151 100644 --- a/docs/Validator/Error.html +++ b/docs/Validator/Error.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Validator::Error - validator master-dev + Validator::Error - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -168,6 +168,13 @@

Defined in:

+ + + validator.cr + + +
+ diff --git a/docs/index.html b/docs/index.html index 97d0096..f89d9e0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - validator master-dev + validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -218,6 +218,18 @@

email: { required: true, + # Optional lifecycle hook to be executed on `check_email` call. + # Before the `check` rules, just after `clean_email` called inside `check_email`. + # Proc or method name (here is a Proc) + before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) { + puts "before_check_content" + content + }, + + # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules. + # Proc or method name (here is the method name) + after_check: :after_check_email + # Checker (all validators are supported) check: { not_empty: {"Email is required"}, @@ -234,8 +246,8 @@

# Here is a String to: :to_s, - # Formatter (any Crystal Proc) - format: ->self.format_email(String), + # Formatter (any Crystal Proc) or method name (Symbol) + format: :format_email, # Error message # Default is "Wrong type" but it can be customized @@ -275,41 +287,48 @@

# --------------------------------------------------------------------------- # Triggered on instance: `user.check` - def before_check(v : Check::Validation, required : Bool, format : Bool) + private def before_check(v : Check::Validation, required : Bool, format : Bool) # Code... end # Triggered on instance: `user.check` - def after_check(v : Check::Validation, required : Bool, format : Bool) + private def after_check(v : Check::Validation, required : Bool, format : Bool) # Code... end # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`) - def self.before_check(v : Check::Validation, h, required : Bool, format : Bool) + private def self.before_check(v : Check::Validation, h, required : Bool, format : Bool) # Code... pp h end # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`) - def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool) + private def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool) # Code... pp cleaned_h cleaned_h # <= returns cleaned_h! end + # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`. + private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool) + puts "after_check_content" + puts "Valid? #{v.valid?}" + content + end + # -------------------------------------------------------------------------- # Custom checkers # -------------------------------------------------------------------------- # Triggered on instance: `user.check` @[Check::Checker] - def custom_checker(v : Check::Validation, required : Bool, format : Bool) + private def custom_checker(v : Check::Validation, required : Bool, format : Bool) # Code... end # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`) @[Check::Checker] - def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool) + private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool) # Code... cleaned_h # <= returns cleaned_h! end diff --git a/docs/index.json b/docs/index.json index 3940afe..b29c358 100644 --- a/docs/index.json +++ b/docs/index.json @@ -1 +1 @@ -{"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.
\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.2.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc)\n format: ->self.format_email(String),\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: \"Age is required\", # Custom message\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"

An (optional) expressive flavor of Validator (or Valid alias).

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":18,"url":null},"def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"

Same as is but raise a Validator::Error displaying an inspection if the validation is false.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":26,"url":null},"def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"

Standalone check module that provides a practical workflow for validations.

","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":377,"url":null},"def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":353,"url":null},"def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

A mixin to make a class checkable.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/checkable.cr","line_number":67,"url":null},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

","abstract":false,"args":[],"args_string":"(**fields)","location":{"filename":"src/checkable.cr","line_number":133,"url":null},"def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false) == false ? false : true\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true, {{ format }}.call(value)\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?\n {% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"

Mixin that adds #check method to be used with variables of an instance of the class including it.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered after each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":451,"url":null},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered before each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":437,"url":null},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":497,"url":null},"def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":467,"url":null},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select do |method|\n method.annotation(Checker)\nend %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"

Mixin that adds .check method to be used with a Hash.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"

Lifecycle method triggered after each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":346,"url":null},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"

Lifecycle method triggered before each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":325,"url":null},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":366,"url":null},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select do |method|\n method.annotation(Checker)\nend %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":419,"url":null},"def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

Returns a Hash from a JSON input.

","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":310,"url":null},"def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"

Macro that returns the mapping of the JSON fields

","abstract":false,"args":[],"args_string":" : Hash(String, String)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":268,"url":null},"def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"

Returns a new Hash with all JSON keys converted to Crystal keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":283,"url":null},"def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"

Returns a new Hash with all Crystal keys converted to JSON keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":293,"url":null},"def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"

Declare a method as a checker.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Validation errors.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"

Combines a series of checks into one validation instance, with a customized error message for each case.

","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation using an existing errors Hash (Check::Errors).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":181,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":166,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":204,"url":null},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":224,"url":null},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":272,"url":null},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":309,"url":null},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":330,"url":null},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Errors container.

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":191,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

Creates a new instance of ValidationError (Exception).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":336,"url":null},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@errors)"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"

Returns true if there is no error, false if there is one or more errors.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":236,"url":null},"def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]},{"html_id":"validator/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

Validation error.

","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":24,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

Returns Errors container (Hash).

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":29,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"

Alias of Validator

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Validator","path":"Validator.html","kind":"module","full_name":"Validator","name":"Validator","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":null},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":null},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"

Validates that the value String is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":null},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"

Validates that the value is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":null},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"

Validates that the value String is comprised in its entirety by ASCII characters.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":null},"def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"

Validates that all the String in the values Array are comprised in their entirety by ASCII characters.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"args_string":"(values : Array(String)) : Bool","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":null},"def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"

Validates that the value has the format base64.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":null},"def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"

Validates that the value is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":null},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"

Validates that the size of the value (String or Array) is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":null},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":23,"url":null},"def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"

Validates that the value is an email.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":158,"url":null},"def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"

Validates that the value is empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":null},"def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":null},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":null},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":null},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"

Validates that the value is equal to another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":null},"def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"

Validates that the value is greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":null},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"

Validates that the size of the value (String or Array) is greater than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":null},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"

Validates that the value is equal to or greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":null},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"

Validates that the size of the value (String or Array) is greater than min number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":null},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"

Validates that the String value does denote a representation of a hexadecimal string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":null},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a hexadecimal slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":null},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"

Validates that the String value does denote a representation of a hexadecimal color.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":null},"def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (str) String contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":null},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":null},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"

Validates that the value is an IP (IPv4 or IPv6).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":77,"url":null},"def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"

Validates that the value is an IPv4.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":82,"url":null},"def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"

Validates that the value is an IPv6.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":87,"url":null},"def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"

Validates that the value represents a JSON string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":null},"def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"

Validates that the value is a JSON Web Token.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":null},"def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical latitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":null},"def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"

Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":null},"def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical longitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":null},"def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"

Validates that the value is in lower case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":null},"def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"

Validates that the size of the value (String or Array) is lesser than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":null},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"

Validates that the value is lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":null},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"

Validates that the size of the value (String or Array) is equal or lesser than max number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":null},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"

Validates that the value is equal to or lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":null},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"

Validates that the value is a MAC address.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":176,"url":null},"def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"

Validates that the value is a Magnet URI.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":186,"url":null},"def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":null},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":null},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"

Validates that the value is equal to or lesser than max (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":null},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":null},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"

Validates that the value has the format md5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":null},"def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"

Validates that the value is equal to or greater than min (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":null},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":null},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a MongoID slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":null},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"

Validates that the String value does denote a representation of a MongoID string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":null},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"

Validates that the value is not empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":null},"def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (str) String does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":null},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":null},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"

Validates that the value is not null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":null},"def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"

Validates that the value is null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":null},"def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"

Validates that the value is a numeric String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":null},"def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":44,"url":null},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":38,"url":null},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":null},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":null},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"

Returns true if the value is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":null},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"

Validates that the value String is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":null},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"

Validates that the value is in the size range.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"

Validates that the value is a slug.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":171,"url":null},"def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":null},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":null},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":null},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"

Validates that the value is a time String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":null},"def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"

Validates that the value is in upper case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":null},"def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"

Validates that the value is a URL.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":52,"url":null},"def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"

Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":null},"def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"

Used by is! when a validation is not true.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}} \ No newline at end of file +{"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.
\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.2.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Optional lifecycle hook to be executed on `check_email` call.\n # Before the `check` rules, just after `clean_email` called inside `check_email`.\n # Proc or method name (here is a Proc)\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n\n # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules.\n # Proc or method name (here is the method name)\n after_check: :after_check_email\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc) or method name (Symbol)\n format: :format_email,\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: \"Age is required\", # Custom message\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n private def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n private def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n private def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n private def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`.\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n private def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"

An (optional) expressive flavor of Validator (or Valid alias).

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":18,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/is.cr#L18"},"def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"

Same as is but raise a Validator::Error displaying an inspection if the validation is false.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":26,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/is.cr#L26"},"def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":11,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L11"},{"filename":"src/checkable.cr","line_number":9,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L9"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"

Standalone check module that provides a practical workflow for validations.

","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":377,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L377"},"def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":353,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L353"},"def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

A mixin to make a class checkable.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/checkable.cr","line_number":67,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L67"},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n after_check: :after_check_email,\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n # Proc or method name (Symbol)\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

","abstract":false,"args":[],"args_string":"(**fields)","location":{"filename":"src/checkable.cr","line_number":145,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L145"},"def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false) == false ? false : true\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true,\n {% if format.is_a?(SymbolLiteral) %}\n {{ format.id }}(value)\n {% else %}\n {{ format }}.call(value)\n {% end %}\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Lifecycle: hook before_check_field\n {% if before_check = rules[\"before_check\"] %}\n {% if before_check.is_a?(SymbolLiteral) %}\n value = {{ before_check.id }}(v, value, required, format)\n {% else %}\n value = {{ before_check }}.call(v, value, required, format)\n {% end %}\n {% end %}\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?\n {% end %}\n {% end %}\n\n # Lifecycle: hook after_check_field\n {% if after_check = rules[\"after_check\"] %}\n {% if after_check.is_a?(SymbolLiteral) %}\n value = {{ after_check.id }}(v, value, required, format)\n {% else %}\n value = {{ after_check }}.call(v, value, required, format)\n {% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":463,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L463"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"

Mixin that adds #check method to be used with variables of an instance of the class including it.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered after each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":486,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L486"},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered before each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":472,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L472"},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":532,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L532"},"def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":502,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L502"},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select(&.annotation(Checker)) %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":301,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L301"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"

Mixin that adds .check method to be used with a Hash.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"

Lifecycle method triggered after each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":381,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L381"},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"

Lifecycle method triggered before each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":360,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L360"},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":401,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L401"},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select(&.annotation(Checker)) %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":454,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L454"},"def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

Returns a Hash from a JSON input.

","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":345,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L345"},"def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"

Macro that returns the mapping of the JSON fields

","abstract":false,"args":[],"args_string":" : Hash(String, String)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":303,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L303"},"def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"

Returns a new Hash with all JSON keys converted to Crystal keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":318,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L318"},"def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"

Returns a new Hash with all Crystal keys converted to JSON keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":328,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L328"},"def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":28,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L28"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"

Declare a method as a checker.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":19,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L19"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Validation errors.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":152,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L152"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"

Combines a series of checks into one validation instance, with a customized error message for each case.

","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation using an existing errors Hash (Check::Errors).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":181,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L181"},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":166,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L166"},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":204,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L204"},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":224,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L224"},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":272,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L272"},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":309,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L309"},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":330,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L330"},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Errors container.

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":191,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L191"},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

Creates a new instance of ValidationError (Exception).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":336,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L336"},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@errors)"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"

Returns true if there is no error, false if there is one or more errors.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":236,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L236"},"def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]},{"html_id":"validator/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":23,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L23"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

Validation error.

","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":24,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L24"},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

Returns Errors container (Hash).

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":29,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L29"},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validator.cr#L124"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"

Alias of Validator

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Validator","path":"Validator.html","kind":"module","full_name":"Validator","name":"Validator","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":116,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validator.cr#L116"},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/alpha_num.cr#L8"},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/case_sensitive.cr#L8"},{"filename":"src/validators/comparisons.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L8"},{"filename":"src/validators/format.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L8"},{"filename":"src/validators/geo.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L8"},{"filename":"src/validators/presence.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L8"},{"filename":"src/validators/uri.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L8"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L47"},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L42"},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"

Validates that the value String is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L180"},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"

Validates that the value is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L189"},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"

Validates that the value String is comprised in its entirety by ASCII characters.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L41"},"def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"

Validates that all the String in the values Array are comprised in their entirety by ASCII characters.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"args_string":"(values : Array(String)) : Bool","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L47"},"def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"

Validates that the value has the format base64.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L87"},"def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"

Validates that the value is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L87"},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"

Validates that the size of the value (String or Array) is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L94"},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":23,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L23"},"def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"

Validates that the value is an email.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":158,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L158"},"def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"

Validates that the value is empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L58"},"def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L243"},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L248"},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L253"},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"

Validates that the value is equal to another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L10"},"def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"

Validates that the value is greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L15"},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"

Validates that the size of the value (String or Array) is greater than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L21"},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"

Validates that the value is equal to or greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L27"},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"

Validates that the size of the value (String or Array) is greater than min number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L34"},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"

Validates that the String value does denote a representation of a hexadecimal string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L112"},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a hexadecimal slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L118"},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"

Validates that the String value does denote a representation of a hexadecimal color.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L129"},"def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L109"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (str) String contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L101"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L129"},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L124"},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L119"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L114"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"

Validates that the value is an IP (IPv4 or IPv6).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":77,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L77"},"def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"

Validates that the value is an IPv4.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L82"},"def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"

Validates that the value is an IPv6.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":87,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L87"},"def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"

Validates that the value represents a JSON string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L64"},"def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"

Validates that the value is a JSON Web Token.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L95"},"def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical latitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L31"},"def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"

Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L16"},"def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical longitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L38"},"def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"

Validates that the value is in lower case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/case_sensitive.cr#L10"},"def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"

Validates that the size of the value (String or Array) is lesser than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L45"},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"

Validates that the value is lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L39"},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"

Validates that the size of the value (String or Array) is equal or lesser than max number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L58"},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"

Validates that the value is equal to or lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L51"},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"

Validates that the value is a MAC address.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":176,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L176"},"def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"

Validates that the value is a Magnet URI.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":186,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L186"},"def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L15"},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L10"},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"

Validates that the value is equal to or lesser than max (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L76"},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L82"},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"

Validates that the value has the format md5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L82"},"def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"

Validates that the value is equal to or greater than min (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L64"},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L70"},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a MongoID slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L143"},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"

Validates that the String value does denote a representation of a MongoID string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L137"},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"

Validates that the value is not empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L71"},"def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (str) String does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L141"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L149"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L154"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L159"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L164"},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L169"},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"

Validates that the value is not null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L89"},"def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"

Validates that the value is null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L82"},"def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"

Validates that the value is a numeric String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/alpha_num.cr#L12"},"def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":44,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L44"},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":38,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L38"},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L31"},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L26"},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"

Returns true if the value is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L209"},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"

Validates that the value String is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L200"},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L122"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L117"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"

Validates that the value is in the size range.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L111"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L105"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L100"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"

Validates that the value is a slug.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":171,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L171"},"def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L226"},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L231"},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L221"},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"

Validates that the value is a time String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L31"},"def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"

Validates that the value is in upper case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/case_sensitive.cr#L15"},"def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"

Validates that the value is a URL.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":52,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L52"},"def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"

Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L103"},"def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/validator.cr","line_number":120,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validator.cr#L120"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"

Used by is! when a validation is not true.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}} \ No newline at end of file diff --git a/docs/search-index.js b/docs/search-index.js index 84dc398..60e5854 100644 --- a/docs/search-index.js +++ b/docs/search-index.js @@ -1 +1 @@ -crystal_doc_search_index_callback({"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.
\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.2.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc)\n format: ->self.format_email(String),\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: \"Age is required\", # Custom message\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"

An (optional) expressive flavor of Validator (or Valid alias).

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":18,"url":null},"def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"

Same as is but raise a Validator::Error displaying an inspection if the validation is false.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":26,"url":null},"def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"

Standalone check module that provides a practical workflow for validations.

","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":377,"url":null},"def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":353,"url":null},"def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

A mixin to make a class checkable.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/checkable.cr","line_number":67,"url":null},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

","abstract":false,"args":[],"args_string":"(**fields)","location":{"filename":"src/checkable.cr","line_number":133,"url":null},"def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false) == false ? false : true\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true, {{ format }}.call(value)\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?\n {% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"

Mixin that adds #check method to be used with variables of an instance of the class including it.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered after each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":451,"url":null},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered before each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":437,"url":null},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":497,"url":null},"def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":467,"url":null},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select do |method|\n method.annotation(Checker)\nend %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"

Mixin that adds .check method to be used with a Hash.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"

Lifecycle method triggered after each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":346,"url":null},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"

Lifecycle method triggered before each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":325,"url":null},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":366,"url":null},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select do |method|\n method.annotation(Checker)\nend %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":419,"url":null},"def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

Returns a Hash from a JSON input.

","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":310,"url":null},"def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"

Macro that returns the mapping of the JSON fields

","abstract":false,"args":[],"args_string":" : Hash(String, String)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":268,"url":null},"def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"

Returns a new Hash with all JSON keys converted to Crystal keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":283,"url":null},"def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"

Returns a new Hash with all Crystal keys converted to JSON keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":293,"url":null},"def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"

Declare a method as a checker.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Validation errors.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"

Combines a series of checks into one validation instance, with a customized error message for each case.

","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation using an existing errors Hash (Check::Errors).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":181,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":166,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":204,"url":null},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":224,"url":null},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":272,"url":null},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":309,"url":null},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":330,"url":null},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Errors container.

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":191,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

Creates a new instance of ValidationError (Exception).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":336,"url":null},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@errors)"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"

Returns true if there is no error, false if there is one or more errors.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":236,"url":null},"def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]},{"html_id":"validator/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

Validation error.

","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":24,"url":null},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

Returns Errors container (Hash).

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":29,"url":null},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"

Alias of Validator

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Validator","path":"Validator.html","kind":"module","full_name":"Validator","name":"Validator","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":null},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":null},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"

Validates that the value String is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":null},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"

Validates that the value is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":null},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"

Validates that the value String is comprised in its entirety by ASCII characters.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":null},"def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"

Validates that all the String in the values Array are comprised in their entirety by ASCII characters.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"args_string":"(values : Array(String)) : Bool","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":null},"def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"

Validates that the value has the format base64.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":null},"def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"

Validates that the value is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":null},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"

Validates that the size of the value (String or Array) is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":null},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":23,"url":null},"def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"

Validates that the value is an email.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":158,"url":null},"def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"

Validates that the value is empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":null},"def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":null},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":null},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":null},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"

Validates that the value is equal to another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":null},"def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"

Validates that the value is greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":null},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"

Validates that the size of the value (String or Array) is greater than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":null},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"

Validates that the value is equal to or greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":null},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"

Validates that the size of the value (String or Array) is greater than min number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":null},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"

Validates that the String value does denote a representation of a hexadecimal string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":null},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a hexadecimal slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":null},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"

Validates that the String value does denote a representation of a hexadecimal color.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":null},"def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (str) String contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":null},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":null},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":null},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"

Validates that the value is an IP (IPv4 or IPv6).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":77,"url":null},"def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"

Validates that the value is an IPv4.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":82,"url":null},"def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"

Validates that the value is an IPv6.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":87,"url":null},"def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"

Validates that the value represents a JSON string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":null},"def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"

Validates that the value is a JSON Web Token.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":null},"def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical latitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":null},"def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"

Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":null},"def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical longitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":null},"def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"

Validates that the value is in lower case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":null},"def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"

Validates that the size of the value (String or Array) is lesser than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":null},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"

Validates that the value is lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":null},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"

Validates that the size of the value (String or Array) is equal or lesser than max number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":null},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"

Validates that the value is equal to or lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":null},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"

Validates that the value is a MAC address.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":176,"url":null},"def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"

Validates that the value is a Magnet URI.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":186,"url":null},"def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":null},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":null},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"

Validates that the value is equal to or lesser than max (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":null},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":null},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"

Validates that the value has the format md5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":null},"def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"

Validates that the value is equal to or greater than min (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":null},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":null},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a MongoID slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":null},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"

Validates that the String value does denote a representation of a MongoID string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":null},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"

Validates that the value is not empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":null},"def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (str) String does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":null},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":null},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":null},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"

Validates that the value is not null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":null},"def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"

Validates that the value is null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":null},"def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"

Validates that the value is a numeric String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":null},"def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":44,"url":null},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":38,"url":null},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":null},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":null},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"

Returns true if the value is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":null},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"

Validates that the value String is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":null},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"

Validates that the value is in the size range.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":null},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"

Validates that the value is a slug.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":171,"url":null},"def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":null},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":null},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":null},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"

Validates that the value is a time String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":null},"def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"

Validates that the value is in upper case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":null},"def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"

Validates that the value is a URL.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":52,"url":null},"def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"

Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":null},"def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"

Used by is! when a validation is not true.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}) \ No newline at end of file +crystal_doc_search_index_callback({"repository_name":"validator","body":"# validator\n\n[![Build Status](https://travis-ci.com/Nicolab/crystal-validator.svg?branch=master)](https://travis-ci.com/Nicolab/crystal-validator) [![GitHub release](https://img.shields.io/github/release/Nicolab/crystal-validator.svg)](https://github.com/Nicolab/crystal-validator/releases) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://nicolab.github.io/crystal-validator/)\n\n∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.
\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](#check) (not exposed by default) provides:\n\n* Error message handling intended for the end user.\n* Also (optional) a powerful and productive system of validation rules.\n With self-generated granular methods for cleaning and checking data.\n\n**Validator** respects the [KISS principle](https://en.wikipedia.org/wiki/KISS_principle) and the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy). It's a great basis tool for doing your own validation logic on top of it.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n validator:\n github: nicolab/crystal-validator\n version: ~> 1.2.0 # Check the latest version!\n```\n\n2. Run `shards install`\n\n## Usage\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\nThere are 3 main ways to use *validator*:\n\n* As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n* As a more advanced validation system which will check a series of rules and returns all validation errors encountered with custom or standard messages.\n* As a system of validation rules (inspired by the _Laravel framework's Validator_)\n which makes data cleaning and data validation in Crystal very easy!\n With self-generated granular methods for cleaning and checking data of each field.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```crystal\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative.\nNot exposed by default, it must be imported:\n\n```crystal\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n* [Validator - API docs](https://nicolab.github.io/crystal-validator/)\n\n### Validation rules\n\n```crystal\nrequire \"validator/check\"\n\nclass User\n # Mixin\n Check.checkable\n\n property email : String\n property age : Int32\n property bio : String?\n\n Check.rules(\n # required\n email: {\n required: true,\n\n # Optional lifecycle hook to be executed on `check_email` call.\n # Before the `check` rules, just after `clean_email` called inside `check_email`.\n # Proc or method name (here is a Proc)\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n\n # Optional lifecycle hook to be executed on `check_email` call, after the `check` rules.\n # Proc or method name (here is the method name)\n after_check: :after_check_email\n\n # Checker (all validators are supported)\n check: {\n not_empty: {\"Email is required\"},\n email: {\"It is not a valid email\"},\n },\n\n # Cleaner\n clean: {\n # Data type\n type: String,\n\n # Converter (if union or other) to the expected value type.\n # Example if the input value is i32, but i64 is expected\n # Here is a String\n to: :to_s,\n\n # Formatter (any Crystal Proc) or method name (Symbol)\n format: :format_email,\n\n # Error message\n # Default is \"Wrong type\" but it can be customized\n message: \"Oops! Wrong type.\",\n },\n },\n\n # required\n age: {\n required: \"Age is required\", # Custom message\n check: {\n min: {\"Age should be more than 18\", 18},\n between: {\"Age should be between 25 and 35\", 25, 35},\n },\n clean: {type: Int32, to: :to_i32, message: \"Unable to cast to Int32\"},\n },\n\n # nilable\n bio: {\n check: {\n between: {\"The user bio must be between 2 and 400 characters.\", 2, 400},\n },\n clean: {\n type: String,\n to: :to_s,\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true\n },\n },\n )\n\n def initialize(@email, @age); end\n\n # ---------------------------------------------------------------------------\n # Lifecycle methods (hooks)\n # ---------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n private def before_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on instance: `user.check`\n private def after_check(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n private def self.before_check(v : Check::Validation, h, required : Bool, format : Bool)\n # Code...\n pp h\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n private def self.after_check(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\n end\n\n # Triggered on a static call and on instance call: `User.check_email(value)`, `User.check(h)`, `user.check`.\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n # --------------------------------------------------------------------------\n # Custom checkers\n # --------------------------------------------------------------------------\n\n # Triggered on instance: `user.check`\n @[Check::Checker]\n private def custom_checker(v : Check::Validation, required : Bool, format : Bool)\n # Code...\n end\n\n # Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\n @[Check::Checker]\n private def self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n # Code...\n cleaned_h # <= returns cleaned_h!\n end\n\n # --------------------------------------------------------------------------\n # Formatters\n # --------------------------------------------------------------------------\n\n # Format (convert) email.\n def self.format_email(email)\n puts \"mail stripped\"\n email.strip\n end\n\n # --------------------------------------------------------------------------\n # Normal methods\n # --------------------------------------------------------------------------\n\n def foo()\n # Code...\n end\n\n def self.bar(v)\n # Code...\n end\n\n # ...\n end\n```\n\n__Check__ with this example class (`User`):\n\n```crystal\n# Check a Hash (statically)\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Check a Hash (on instance)\nuser = user.new(\"demo@example.org\", 38)\n\nv = user.check # => Validation instance\npp v.valid?\npp v.errors\n\n# Check field\nv, email = User.check_email(value: \"demo@example.org\")\nv, age = User.check_age(value: 42)\n\nv, email = User.check_email(value: \"demo@example.org \", format: true)\nv, email = User.check_email(value: \"demo@example.org \", format: false)\n\n# Using an existing Validation instance\nv = Check.new_validation\nv, email = User.check_email(v, value: \"demo@example.org\")\n```\n\n__Clean__ with this example class (`User`):\n\n```crystal\n# `check` method cleans all values of the Hash (or JSON::Any),\n# before executing the validation rules\nv, user_h = User.check(input_h)\n\npp v # => Validation instance\npp v.valid?\npp v.errors\n\npp user_h # => Casted and cleaned Hash\n\n# Cast and clean field\nok, email = User.clean_email(value: \"demo@example.org\")\nok, age = User.clean_age(value: 42)\n\nok, email = User.clean_email(value: \"demo@example.org \", format: true)\nok, email = User.clean_email(value: \"demo@example.org \", format: false)\n\nputs \"${email} is casted and cleaned\" if ok\n# or\nputs \"Email type error\" unless ok\n```\n\n* `clean_*` methods are useful to caste a union value (like `Hash` or `JSON::Any`).\n* Also `clean_*` methods are optional and handy for formatting values, such as the strip on the email in the example `User` class.\n\nMore details about cleaning, casting, formatting and return values:\n\nBy default `format` is `true`, to disable:\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\", format: false)\n# or\nok, email = User.clean_email(\"demo@example.org\", false)\n```\n\nAlways use named argument if there is only one (the `value`):\n\n```crystal\nok, email = User.clean_email(value: \"demo@example.org\")\n```\n\n`ok` is a boolean value that reports whether the cast succeeded. Like the type assertions in _Go_ (lang).\nBut the `ok` value is returned in first (like in _Elixir_ lang) for easy handling of multiple return values (`Tuple`).\n\nExample with multiple values returned:\n\n```crystal\nok, value1, value2 = User.clean_my_tuple({1, 2, 3})\n```\n\nConsidering the example class above (`User`).\nAs a reminder, the email field has been defined with the formatter below:\n\n```crystal\nCheck.rules(\n email: {\n clean: {\n type: String,\n to: :to_s,\n format: ->self.format_email(String), # <= Here!\n message: \"Wrong type\",\n },\n },\n)\n\n# ...\n\n# Format (convert) email.\ndef self.format_email(email)\n puts \"mail stripped\"\n email.strip\nend\n```\n\nSo `clean_email` cast to `String` and strip the value `\" demo@example.org \"`:\n\n```crystal\n# Email value with one space before and one space after\nok, email = User.clean_email(value: \" demo@example.org \")\n\nputs email # => \"demo@example.org\"\n```\n\nIf the email was taken from a union type (`json[\"email\"]?`), the returned `email` variable would be a `String` too.\n\nSee [more examples](https://github.com/Nicolab/crystal-validator/tree/master/examples).\n\n> NOTE: Require more explanations about `required`, `nilable` rules.\n> Also about the converters JSON / Crystal Hash: `h_from_json`, `to_json_h`, `to_crystal_h`.\n> In the meantime see the [API doc](https://nicolab.github.io/crystal-validator/Check/Checkable.html).\n\n### Validation#check\n\nTo perform a series of validations with error handling, the [validator/check](https://nicolab.github.io/crystal-validator/Check.html) module offers this possibility 👍\n\nA [Validation](https://nicolab.github.io/crystal-validator/Check/Validation.html) instance provides the means to write sequential checks, fine-tune each micro-validation with their own rules and custom error message, the possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\n that provide a powerful and productive system of validation rules\n which makes data cleaning and data validation in Crystal very easy.\n With self-generated granular methods for cleaning and checking data.\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```crystal\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# Print all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```crystal\n# check(key : Symbol | String, valid : Bool)\n# Using default error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\nThe `Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```crystal\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n\n### Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```crystal\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\nUsing the custom validator with the validation rules:\n\n```crystal\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```\n\n## Conventions\n\n* The word \"validator\" is the method to make a \"validation\" (value validation).\n* A *validator* returns `true` if the value (or/and the condition) is valid, `false` if not.\n* The first argument(s) is (are) the value(s) to be validated.\n* Always add the `Bool` return type to a *validator*.\n* Always add the suffix `?` to the method name of a *validator*.\n* If possible, indicates the type of the *validator* arguments.\n* Spec: Battle tested.\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle) and [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy).\n\n## Development\n\n```sh\ncrystal spec\ncrystal tool format\n```\n\n> TODO: add `ameba`?\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## LICENSE\n\n[MIT](https://github.com/Nicolab/crystal-validator/blob/master/LICENSE) (c) 2020, Nicolas Talle.\n\n## Author\n\n| [![Nicolas Tallefourtane - Nicolab.net](https://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](https://github.com/sponsors/Nicolab) |\n|---|\n| [Nicolas Talle](https://github.com/sponsors/Nicolab) |\n| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |\n\n> Thanks to [ilourt](https://github.com/ilourt) for his great work on `checkable` mixins (clean_*, check_*, ...).\n","program":{"html_id":"validator/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"validator","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[{"id":"is(name,*args)-macro","html_id":"is(name,*args)-macro","name":"is","doc":"An (optional) expressive flavor of `Validator` (or `Valid` alias).\nNot exposed by default, must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis \"email?\", \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\n```","summary":"

An (optional) expressive flavor of Validator (or Valid alias).

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":18,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/is.cr#L18"},"def":{"name":"is","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n"}},{"id":"is!(name,*args)-macro","html_id":"is!(name,*args)-macro","name":"is!","doc":"Same as `is` but `raise` a `Validator::Error`\ndisplaying an inspection if the validation is `false`.\nUseful for the unit tests :)","summary":"

Same as is but raise a Validator::Error displaying an inspection if the validation is false.

","abstract":false,"args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(name, *args)","location":{"filename":"src/is.cr","line_number":26,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/is.cr#L26"},"def":{"name":"is!","args":[{"name":"name","doc":null,"default_value":"","external_name":"name","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"block_arg":null,"visibility":"Public","body":" \n# Symbol ? String\n\n valid = Valid.\n{{ name.id }}\n \n{{ args.splat }}\n\n\n if valid == false\n raise Validator::Error.new \"Is not \\\"#{\n{{ name }}\n}\\\":\\n#{\n{{ args.stringify }}\n}\"\n \nend\n\n true\n\n"}}],"types":[{"html_id":"validator/Check","path":"Check.html","kind":"module","full_name":"Check","name":"Check","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":11,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L11"},{"filename":"src/checkable.cr","line_number":9,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L9"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Standalone check module that provides a practical workflow for validations.","summary":"

Standalone check module that provides a practical workflow for validations.

","class_methods":[{"id":"new_validation(errors:Errors)-class-method","html_id":"new_validation(errors:Errors)-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\nusing an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check.new_validation existing_errors\n```\n\nSame as:\n\n```\nv = Check::Validation.new existing_errors\n```\n\nExample to combine two hashes of validation errors:\n\n```\npreview_validation = Check.new_validation\nv = Check.new_validation preview_validation.errors\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":377,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L377"},"def":{"name":"new_validation","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new(errors)"}},{"id":"new_validation-class-method","html_id":"new_validation-class-method","name":"new_validation","doc":"Initializes a new `Validation` instance to combine\na series of checks (`Validation#check`).\n\n```\nv = Check.new_validation\n```\n\nSame as:\n\n```\nv = Check::Validation.new\n```","summary":"

Initializes a new Validation instance to combine a series of checks (Validation#check).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":353,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L353"},"def":{"name":"new_validation","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Validation.new"}}],"constructors":[],"instance_methods":[],"macros":[{"id":"checkable-macro","html_id":"checkable-macro","name":"checkable","doc":"A mixin to make a class checkable.\nThis mixin includes `Checkable` and `CheckableStatic`.\nIt must be used in conjonction with `Check.rules`.\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n )\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

A mixin to make a class checkable.

","abstract":false,"args":[],"args_string":"","location":{"filename":"src/checkable.cr","line_number":67,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L67"},"def":{"name":"checkable","args":[],"double_splat":null,"splat_index":null,"block_arg":null,"visibility":"Public","body":" include Check::Checkable\n \nextend Check::CheckableStatic\n \n"}},{"id":"rules(**fields)-macro","html_id":"rules(**fields)-macro","name":"rules","doc":"Generates `check`, `check_{{field}}` and `clean_{{field}}` methods for *fields* (class variables).\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n property url : String?\n\n private def self.after_check_content(v : Check::Validation, content : String?, required : Bool, format : Bool)\n puts \"after_check_content\"\n puts \"Valid? #{v.valid?}\"\n content\n end\n\n Check.rules(\n content: {\n required: \"Content is required\", # or `true` to use the default error message\n before_check: ->(v : Check::Validation, content : String?, required : Bool, format : Bool) {\n puts \"before_check_content\"\n content\n },\n after_check: :after_check_email,\n check: {\n not_empty: {\"Article content is required\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n clean: {\n type: String,\n to: :to_s,\n # Proc or method name (Symbol)\n format: ->(content : String) { content.strip },\n message: \"Wrong type\",\n },\n },\n url: {\n check: {\n url: {\"Article URL is invalid\"},\n },\n clean: {\n # `nilable` means omited if not provided,\n # regardless of Crystal type (nilable or not)\n nilable: true,\n # Crystal type\n type: String,\n # Converter to the expected typed value\n to: :to_s,\n },\n },\n # ...\n)\nend\n\n# Triggered on all data\nv, article = Article.check(input_data)\n\n# Triggered on all fields of an instance\narticle = Article.new(title: \"foo\", content: \"bar\")\nv = article.check\n\n# Triggered on a value\nv, content = Article.check_content(input_data[\"content\"]?)\n\n# Cast and clean a value\nok, content = Article.clean_content(input_data[\"content\"]?)\n```\n\nSee also `Check.checkable`.","summary":"

Generates check, check_{{field}} and clean_{{field}} methods for fields (class variables).

","abstract":false,"args":[],"args_string":"(**fields)","location":{"filename":"src/checkable.cr","line_number":145,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L145"},"def":{"name":"rules","args":[],"double_splat":{"name":"fields","doc":null,"default_value":"","external_name":"fields","restriction":""},"splat_index":null,"block_arg":null,"visibility":"Public","body":" private def self.validation_rules\n \n{{ fields }}\n\n \nend\n\n private def self.validation_required?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil?\n fields[field].fetch(\"required\", false) == false ? false : true\n \nend\n\n private def self.validation_nilable?(field) : Bool\n fields = self.validation_rules\n return false if fields[field].nil? || fields[field][\"clean\"].nil?\n fields[field][\"clean\"].fetch(\"nilable\", false).as(Bool)\n \nend\n\n \n{% for field, rules in fields %}\n {% clean = rules[\"clean\"] %}\n {% check = rules[\"check\"] %}\n {% type = clean[\"type\"] %}\n {% nilable = clean[\"nilable\"] %}\n\n # Returns *{{ field }}* with the good type and formatted if *format* is `true`.\n # The return type is a tuple with a bool as a first argument indicating\n # that the clean has been processed successfully or not and the 2nd\n # argument is the *value* cleaned.\n #\n # ```\n # ok, email = Checkable.clean_email(user_input[\"email\"]) # => true, user@example.com\n # ```\n def self.clean_{{ field }}(value, format = true) : Tuple(Bool, {{ type }} | Nil)\n # force real Nil type (hack for JSON::Any and equivalent)\n value = nil if value == nil\n\n {% if to = clean[\"to\"] %}\n # Check if the *value* has the method `{{ to }}` and execute it if\n # exists to cast the value in the good type (except if the value is nil and nilable).\n if value.responds_to? {{ to }} {% if nilable %} && !value.nil?{% end %}\n begin\n value = value.{{ to.id }}\n rescue\n return false, nil\n end\n end\n {% end %}\n\n # Format if the value as the correct (Crystal) type.\n # `| Nil` allows to format in the case of a nilable value (example `String?`)\n # where the `type` option of `clean` rules has been defined on the precise\n # Crystal type (example `String`).\n if value.is_a? {{ type }} | Nil\n {% if format = clean[\"format\"] %}\n # If *format* is true then call it to format *value*.\n if format\n begin\n return true,\n {% if format.is_a?(SymbolLiteral) %}\n {{ format.id }}(value)\n {% else %}\n {{ format }}.call(value)\n {% end %}\n rescue\n return false, nil\n end\n else\n return true, value\n end\n {% else %}\n return true, value\n {% end %}\n end\n\n {false, nil}\n end\n\n # Create a new `Check::Validation` and checks *{{ field }}*.\n # For more infos check `.check_{{ field }}(v : Check::Validation, value, format : Bool = true)`\n def self.check_{{ field }}(\n *,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n v = Check.new_validation\n self.check_{{ field }}(v, value, required, format)\n end\n\n # Cleans and check *value*.\n # If *format* is `true` it tells `.clean_{{ field }}` to execute the `format` function\n # for this field if it has been defined with `Check.rules`.\n def self.check_{{ field }}(\n v : Check::Validation,\n value,\n required : Bool = true,\n format : Bool = true\n ) : Tuple(Check::Validation, {{ type }} | Nil)\n # Cleans and formats the *value*\n ok, value = self.clean_{{ field }}(value, format)\n\n # If clean has encountered an error, add error message and stop check here.\n if ok == false\n {% msg = clean[\"message\"] || \"Wrong type\" %}\n v.add_error(\n {{ field.stringify }},\n {{ msg }}\n ) {% if nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?) %}unless value.nil?{% end %}\n\n return v, value\n end\n\n # Lifecycle: hook before_check_field\n {% if before_check = rules[\"before_check\"] %}\n {% if before_check.is_a?(SymbolLiteral) %}\n value = {{ before_check.id }}(v, value, required, format)\n {% else %}\n value = {{ before_check }}.call(v, value, required, format)\n {% end %}\n {% end %}\n\n # Check against each rule provided.\n # Each rule is executed if *value* is not `nil` except for `not_null` and `not_empty`\n # which is executed even if the *value* is `nil`\n {% for name, args in check %}\n v.check(\n {{ field.stringify }},\n {{ args[0] }},\n {% if args.size <= 1 %}\n Valid.{{ name.id }}? value\n {% else %}\n Valid.{{ name.id }}? value, {{ args[1..-1].splat }}\n {% end %}\n ) {% if (nilable || (check[\"not_null\"].nil? && check[\"not_empty\"].nil?)) || ((name != \"not_null\") && (name != \"not_empty\")) %}unless value.nil?\n {% end %}\n {% end %}\n\n # Lifecycle: hook after_check_field\n {% if after_check = rules[\"after_check\"] %}\n {% if after_check.is_a?(SymbolLiteral) %}\n value = {{ after_check.id }}(v, value, required, format)\n {% else %}\n value = {{ after_check }}.call(v, value, required, format)\n {% end %}\n {% end %}\n\n {v, value}\n end\n {% end %}\n\n \n"}}],"types":[{"html_id":"validator/Check/Checkable","path":"Check/Checkable.html","kind":"module","full_name":"Check::Checkable","name":"Checkable","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":463,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L463"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `#check` method to be used with variables of an instance of the class including it.\nThe idea is to check the instance variables of the class extending it\nagainst rules defined with `Check.rules` plus executing custom checkers defined with `Checker`.","summary":"

Mixin that adds #check method to be used with variables of an instance of the class including it.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"after_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef after_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered after each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":486,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L486"},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `#check`.\n\n```\n# Triggered on instance: `user.check`\ndef before_check(v : Check::Validation, required : Bool = true, format : Bool = true)\n # Code...\nend\n```","summary":"

Lifecycle method triggered before each call of #check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":472,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L472"},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(required : Bool = true, format : Bool = true) : Validation","args_html":"(required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":532,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L532"},"def":{"name":"check","args":[{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"v = Check.new_validation\ncheck(v, required, format)\n"}},{"id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","html_id":"check(v:Check::Validation,required:Bool=true,format:Bool=true):Validation-instance-method","name":"check","doc":"Checks the instance fields and clean them.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to rules and then methods defined with annotation `Checker`.\n\nLifecycle methods `#before_check` and `#after_check` that are triggered\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks the instance fields and clean them.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","args_html":"(v : Check::Validation, required : Bool = true, format : Bool = true) : Validation","location":{"filename":"src/checkable.cr","line_number":502,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L502"},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"{% if true %}\n\n # Call lifecycle method before check\n before_check v, required, format\n\n # Check all fields that have a method `#check_{field}`\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n v, value = self.class.check_{{ ivar.name }}(v, {{ ivar.name }}, required, format)\n\n # If the field is not nilable and the value is nil,\n # it means that the clean method has failed\n # (to cast or an exception has been raised (and catched) in the formatter)\n # So ignore the nil value if the field is not nilable\n @{{ ivar.name }} = value.as({{ ivar.type }}) {% if !ivar.type.nilable? %} unless value.nil? {% end %}\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.methods.select(&.annotation(Checker)) %}\n {{ method.name }} v, required, format\n {% end %}\n\n # Call lifecycle method `#after_check`\n after_check v, required, format\n\n v\n {% end %}"}}],"macros":[],"types":[]},{"html_id":"validator/Check/CheckableStatic","path":"Check/CheckableStatic.html","kind":"module","full_name":"Check::CheckableStatic","name":"CheckableStatic","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":301,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L301"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Mixin that adds `.check` method to be used with a `Hash`.\nThe idea is to check a `Hash` against rules defined with `Check.rules`\nplus executing custom checkers defined with `Checker` annotation.","summary":"

Mixin that adds .check method to be used with a Hash.

","class_methods":[],"constructors":[],"instance_methods":[{"id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","html_id":"after_check(v:Check::Validation,h:Hash,cleaned_h:Hash,required:Bool=true,format:Bool=true):Hash-instance-method","name":"after_check","doc":"Lifecycle method triggered after each call of `.check`.\n\nThis method (in static call) must returns the cleaned `Hash`\nwhich is provided in the third argument.\nYou can update this cleaned hash but you have to return it.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.after_check(v : Check::Validation, h, cleaned_h, required : Bool = true, format : Bool = true) : Hash\n # Code...\n pp cleaned_h\n cleaned_h # <= returns cleaned_h!\nend\n```","summary":"

Lifecycle method triggered after each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","args_html":"(v : Check::Validation, h : Hash, cleaned_h : Hash, required : Bool = true, format : Bool = true) : Hash","location":{"filename":"src/checkable.cr","line_number":381,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L381"},"def":{"name":"after_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"cleaned_h","doc":null,"default_value":"","external_name":"cleaned_h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cleaned_h"}},{"id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"before_check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"before_check","doc":"Lifecycle method triggered before each call of `.check`.\n\n```\n# Triggered on a static call: `User.check(h)` (with a `Hash` or `JSON::Any`)\ndef self.before_check(v : Check::Validation, h, required : Bool = true, format : Bool = true)\n # Code...\n pp h\nend\n```","summary":"

Lifecycle method triggered before each call of .check.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":360,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L360"},"def":{"name":"before_check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(v:Check::Validation,h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","args_html":"(v : Check::Validation, h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":401,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L401"},"def":{"name":"check","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":"Check::Validation"},{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"{% if true %}\n {% types = [] of Type %}\n {% fields = [] of String %}\n\n {% for ivar in @type.instance_vars.select do |ivar|\n @type.class.has_method?(\"check_#{ivar}\")\nend %}\n {% types << ivar.type %}\n {% fields << ivar.name %}\n {% end %}\n\n # Instantiate a `Hash` with keys as `String` and values as a union of\n # all types of fields which have a method `.check_{field}`\n cleaned_h = Hash(String, {{ (types.join(\"|\")).id }}).new\n\n # Call lifecycle method before check\n self.before_check v, h, required, format\n\n # Call check methods for fields that are present in *h*\n # and populate `cleaned_h`\n {% for field, i in fields %}\n {% field_name = field.stringify %}\n # if hash has the field\n if h.has_key?({{ field_name }})\n v, value = self.check_{{ field }}(v, h[{{ field_name }}]?, required, format)\n cleaned_h[{{ field_name }}] = value.as({{ types[i] }})\n\n # or if this field MUST be checked when required\n elsif required && self.validation_required?({{ field_name }})\n required_msg = self.validation_rules[{{ field_name }}].fetch(:required, nil)\n\n msg = if required_msg && required_msg.is_a?(String)\n required_msg.as(String)\n else\n \"This field is required\"\n end\n\n v.add_error {{ field_name }}, msg\n end\n {% end %}\n\n # Check methods with `Check::Checker` annotation\n {% for method in @type.class.methods.select(&.annotation(Checker)) %}\n cleaned_h = {{ method.name }} v, h, cleaned_h, required, format\n {% end %}\n\n # Call lifecycle method `.after_check`\n cleaned_h = self.after_check v, h, cleaned_h, required, format\n\n {v, cleaned_h}\n {% end %}"}},{"id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","html_id":"check(h:Hash,required:Bool=true,format:Bool=true)-instance-method","name":"check","doc":"Checks and clean the `Hash` for its fields corresponding\nto class variables that have a `.check_{{field}}` method.\n\nIt instantiates a `Check::Validation` (if not provided) and calls all methods\nrelated to `.rules` and then methods defined with annotation `Checker`.\n\nLifecycle methods `.before_check` and `.after_check` that are called\nrespectively at the beginning and at the end of the process.\n\n*format* is used to tell cleaners generated by `Check.rules`\nto execute format method if it has been defined.","summary":"

Checks and clean the Hash for its fields corresponding to class variables that have a .check_{{field}} method.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"args_string":"(h : Hash, required : Bool = true, format : Bool = true)","args_html":"(h : Hash, required : Bool = true, format : Bool = true)","location":{"filename":"src/checkable.cr","line_number":454,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L454"},"def":{"name":"check","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"},{"name":"required","doc":null,"default_value":"true","external_name":"required","restriction":"Bool"},{"name":"format","doc":null,"default_value":"true","external_name":"format","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = Check.new_validation\ncheck(v, h, required, format)\n"}},{"id":"h_from_json(json:String|IO)-instance-method","html_id":"h_from_json(json:String|IO)-instance-method","name":"h_from_json","doc":"Returns a `Hash` from a JSON input.\nThe return type is a tuple with a bool as a first argument indicating\nthat the `JSON.parse` has been processed successfully or not and the 2nd\nargument is the *json* Hash.\n\n```\nok, user_h = User.h_from_json(json) # => true, {\"username\" => \"Bob\", \"email\" => \"user@example.com\"}\n```","summary":"

Returns a Hash from a JSON input.

","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"args_string":"(json : String | IO)","args_html":"(json : String | IO)","location":{"filename":"src/checkable.cr","line_number":345,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L345"},"def":{"name":"h_from_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"String | IO"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"begin\n return {true, self.to_crystal_h((JSON.parse(json)).as_h)}\nrescue\n return {false, nil}\nend"}},{"id":"map_json_keys:Hash(String,String)-instance-method","html_id":"map_json_keys:Hash(String,String)-instance-method","name":"map_json_keys","doc":"Macro that returns the mapping of the JSON fields","summary":"

Macro that returns the mapping of the JSON fields

","abstract":false,"args":[],"args_string":" : Hash(String, String)","args_html":" : Hash(String, String)","location":{"filename":"src/checkable.cr","line_number":303,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L303"},"def":{"name":"map_json_keys","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash(String, String)","visibility":"Public","body":"map = {} of String => String\n{% if true %}\n {% for ivar in @type.instance_vars %}\n {% ann = ivar.annotation(::JSON::Field) %}\n {% if ann && ann[:ignore] %}{% else %}\n map[{{ ((ann && ann[:key]) || ivar).id.stringify }}] = {{ ivar.id.stringify }}\n {% end %}\n {% end %}\n {% end %}\nmap\n"}},{"id":"to_crystal_h(h:Hash):Hash-instance-method","html_id":"to_crystal_h(h:Hash):Hash-instance-method","name":"to_crystal_h","doc":"Returns a new `Hash` with all JSON keys converted to Crystal keys.","summary":"

Returns a new Hash with all JSON keys converted to Crystal keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":318,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L318"},"def":{"name":"to_crystal_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |cr_k|\n cr_keys[cr_k]? || cr_k\nend\n"}},{"id":"to_json_h(h:Hash):Hash-instance-method","html_id":"to_json_h(h:Hash):Hash-instance-method","name":"to_json_h","doc":"Returns a new `Hash` with all Crystal keys converted to JSON keys.","summary":"

Returns a new Hash with all Crystal keys converted to JSON keys.

","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"args_string":"(h : Hash) : Hash","args_html":"(h : Hash) : Hash","location":{"filename":"src/checkable.cr","line_number":328,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L328"},"def":{"name":"to_json_h","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Hash","visibility":"Public","body":"cr_keys = map_json_keys\nh.transform_keys do |json_k|\n cr_keys.key_for?(json_k || json_k)\nend\n"}}],"macros":[],"types":[]},{"html_id":"validator/Check/Checker","path":"Check/Checker.html","kind":"annotation","full_name":"Check::Checker","name":"Checker","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/checkable.cr","line_number":28,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/checkable.cr#L28"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Declare a method as a checker.\n\n```\n# Triggered by the instance.\n@[Check::Checker]\ndef custom_checker(v : Check::Validation, required : Bool, format : Bool)\n puts \"custom checker triggered on instance\"\nend\n\n# Triggered statically.\n@[Check::Checker]\ndef self.custom_checker(v : Check::Validation, h, cleaned_h, required : Bool, format : Bool)\n puts \"custom checker triggered statically\"\n cleaned_h\nend\n```\n\nWhen `.check` and `#check` are called, the custom checkers are triggered respectively.","summary":"

Declare a method as a checker.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Errors","path":"Check/Errors.html","kind":"alias","full_name":"Check::Errors","name":"Errors","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/check.cr","line_number":19,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L19"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Hash(String | Symbol, Array(String))","aliased_html":"Hash(String | Symbol, Array(String))","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation errors.\nIt's a `Hash` used as a container of errors, in order to handle them easily.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Validation errors.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Check/Validation","path":"Check/Validation.html","kind":"class","full_name":"Check::Validation","name":"Validation","abstract":false,"superclass":{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":152,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L152"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Combines a series of checks into one validation instance,\nwith a customized error message for each case.\n\nA `Validation` instance provides the means to write sequential checks,\nfine-tune each micro-validation with their own rules and custom error message,\nthe possibility to retrieve all error messages, etc.\n\n> `Validation` is also used with `Check.rules` and `Check.checkable`\nthat provide a powerful and productive system of validation rules\nwhich makes data cleaning and data validation in Crystal very easy.\nWith self-generated granular methods for cleaning and checking data.\n\n\nTo use the checker (`check`) includes in the `Validation` class:\n\n```\nrequire \"validator/check\"\n\n# Validates the *user* data received in the HTTP controller or other.\ndef validate_user(user : Hash) : Check::Validation\n v = Check.new_validation\n\n # -- email\n\n # Hash key can be a String or a Symbol\n v.check :email, \"The email is required.\", is :presence?, :email, user\n\n v.check \"email\", \"The email is required.\", is :presence?, \"email\", user\n v.check \"email\", \"#{user[\"email\"]} is an invalid email.\", is :email?, user[\"email\"]\n\n # -- username\n\n v.check \"username\", \"The username is required.\", is :presence?, \"username\", user\n\n v.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is :min?, user[\"username\"], 2\n )\n\n v.check(\n \"username\",\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[\"username\"], 20\n )\nend\n\nv = validate_user user\n\npp v.valid? # => true (or false)\n\n# Inverse of v.valid?\nif v.errors.empty?\n return \"no error\"\nend\n\n# display all the errors (if any)\npp v.errors\n\n# It's a Hash of Array\nerrors = v.errors\n\nputs errors.size\nputs errors.first_value\n\nerrors.each do |key, messages|\n puts key # => \"username\"\n puts messages # => [\"The username is required.\", \"etc...\"]\nend\n```\n\n3 methods [#check](https://nicolab.github.io/crystal-validator/Check/Validation.html#instance-method-summary):\n\n```\n# check(key : Symbol | String, valid : Bool)\n# Using default standard error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, message : String, valid : Bool)\n# Using custom error message\nv.check(\n \"username\",\n \"The username must contain at least 2 characters.\",\n is(:min?, user[\"username\"], 2)\n)\n\n# check(key : Symbol | String, valid : Bool, message : String)\n# Using custom error message\nv.check(\n \"username\",\n is(:min?, user[\"username\"], 2),\n \"The username must contain at least 2 characters.\"\n)\n```\n\n`Check` is a simple and lightweight wrapper.\n`Check::Validation` is agnostic of the checked data,\nof the context (model, controller, CSV file, HTTP data, socket data, JSON, etc).\n\n> Use case example:\n Before saving to the database or process user data for a particular task,\n the custom error messages can be used for the end user response.\n\nBut a `Validation` instance can be used just to store validation errors:\n\n```\nv = Check.new_validation\nv.add_error(\"foo\", \"foo error!\")\npp v.errors # => {\"foo\" => [\"foo error!\"]}\n```\n\n> See also `Check.rules` and `Check.checkable`.\n\nLet your imagination run wild to add your logic around it.\n","summary":"

Combines a series of checks into one validation instance, with a customized error message for each case.

","class_methods":[],"constructors":[{"id":"new(errors:Errors)-class-method","html_id":"new(errors:Errors)-class-method","name":"new","doc":"Initializes a validation using an existing *errors* `Hash` (`Check::Errors`).\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation using an existing errors Hash (Check::Errors).

","abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"args_string":"(errors : Errors)","args_html":"(errors : Errors)","location":{"filename":"src/check.cr","line_number":181,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L181"},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Initializes a validation.\n\n```\nv = Check::Validation.new\n```\n\nSame as:\n\n```\nv = Check.new_validation\n```","summary":"

Initializes a validation.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":166,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L166"},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"add_error(key:Symbol|String,message:String):Validation-instance-method","html_id":"add_error(key:Symbol|String,message:String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n```\nv = Check.new_validation\nv.add_error(:foo, \"Foo error!\")\npp v.errors # => {:foo => [\"Foo error!\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, message : String) : Validation","args_html":"(key : Symbol | String, message : String) : Validation","location":{"filename":"src/check.cr","line_number":204,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L204"},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if message.blank?\n message = \"\\\"#{key}\\\" is not valid.\"\nend\nif @errors.has_key?(key)\nelse\n @errors[key] = Array(String).new\nend\n@errors[key] << message\nself\n"}},{"id":"add_error(key:Symbol|String):Validation-instance-method","html_id":"add_error(key:Symbol|String):Validation-instance-method","name":"add_error","doc":"Add a validation error.\n\n> By default a standard message is used.\n\n```\nv = Check.new_validation\nv.add_error(:foo)\npp v.errors # => {:foo => [\"\\\"foo\\\" is not valid.\"]}\n```\n\nSee also: `Errors`","summary":"

Add a validation error.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"args_string":"(key : Symbol | String) : Validation","args_html":"(key : Symbol | String) : Validation","location":{"filename":"src/check.cr","line_number":224,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L224"},"def":{"name":"add_error","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"add_error(key, \"\")\nself\n"}},{"id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,message:String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check :email, \"The email is required.\", is :presence?, :email, user\nv.check :email, \"#{user[:email]} is an invalid email.\", is :email?, user[:email]?\n\n# -- username\n\nv.check :username, \"The username is required.\", is :presence?, :username, user\n\nv.check(\n :username,\n \"The username must contain at least 2 characters.\",\n is :min?, user[:username]?, 2\n)\n\nv.check(\n :username,\n \"The username must contain a maximum of 20 characters.\",\n is :max?, user[:username]?, 20\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, message : String, valid : Bool) : Validation","args_html":"(key : Symbol | String, message : String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":272,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L272"},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool,message:String):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, the error *message* is added in the `errors`.\nNothing if *valid* is `true`.\n\n```\nv = Check.new_validation\n\n# -- email\n\nv.check(:email, is(:presence?, :email, user), \"The email is required.\")\nv.check(:email, is(:email?, user[:email]?), \"#{user[:email]} is an invalid email.\")\n\n# -- username\n\nv.check(:username, is(:presence?, :username, user), \"The username is required.\")\n\nv.check(\n :username,\n is :min?, user[:username]?, 2,\n \"The username must contain at least 2 characters.\"\n)\n\nv.check(\n :username,\n is :max?, user[:username]?, 20,\n \"The username must contain a maximum of 20 characters.\"\n)\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"args_string":"(key : Symbol | String, valid : Bool, message : String) : Validation","args_html":"(key : Symbol | String, valid : Bool, message : String) : Validation","location":{"filename":"src/check.cr","line_number":309,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L309"},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"},{"name":"message","doc":null,"default_value":"","external_name":"message","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, message)\nend\nself\n"}},{"id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","html_id":"check(key:Symbol|String,valid:Bool):Validation-instance-method","name":"check","doc":"Checks a validation, often used in sequence.\n\nIf *valid* is `false`, an error message is added in the `errors`.\nNothing if *valid* is `true`.\n\n> Unlike other `check` methods, with this one a default standard message is used.\n\n```\nv = Check.new_validation\n\nv.check(\"email\", Valid.presence?(\"email\", user))\nv.check(\"email\", Valid.email?(user[\"email\"]?))\n\n# Print all errors\npp v.errors\n```","summary":"

Checks a validation, often used in sequence.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"args_string":"(key : Symbol | String, valid : Bool) : Validation","args_html":"(key : Symbol | String, valid : Bool) : Validation","location":{"filename":"src/check.cr","line_number":330,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L330"},"def":{"name":"check","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"valid","doc":null,"default_value":"","external_name":"valid","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Validation","visibility":"Public","body":"if valid\nelse\n add_error(key, \"\")\nend\nself\n"}},{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Errors container.\n\n```\nv = Check.new_validation\npp v.errors\n```","summary":"

Errors container.

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":191,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L191"},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}},{"id":"to_exception-instance-method","html_id":"to_exception-instance-method","name":"to_exception","doc":"Creates a new instance of `ValidationError` (`Exception`).","summary":"

Creates a new instance of ValidationError (Exception).

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":336,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L336"},"def":{"name":"to_exception","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ValidationError.new(@errors)"}},{"id":"valid?-instance-method","html_id":"valid?-instance-method","name":"valid?","doc":"Returns `true` if there is no error, `false` if there is one or more errors.\n\n```\npp v.errors if !v.valid?\n# or with another flavor ;-)\npp v.errors unless v.valid?\n```","summary":"

Returns true if there is no error, false if there is one or more errors.

","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/check.cr","line_number":236,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L236"},"def":{"name":"valid?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@errors.empty?"}}],"macros":[],"types":[]},{"html_id":"validator/Check/ValidationError","path":"Check/ValidationError.html","kind":"class","full_name":"Check::ValidationError","name":"ValidationError","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/check.cr","line_number":23,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L23"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Check","kind":"module","full_name":"Check","name":"Check"},"doc":"Validation error.\nTo carry `Errors` into an `Exception`.","summary":"

Validation error.

","class_methods":[],"constructors":[{"id":"new(errors:Errors,message="Validationerror")-class-method","html_id":"new(errors:Errors,message="Validationerror")-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"args_string":"(errors : Errors, message = "Validation error")","args_html":"(errors : Errors, message = "Validation error")","location":{"filename":"src/check.cr","line_number":24,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L24"},"def":{"name":"new","args":[{"name":"errors","doc":null,"default_value":"","external_name":"errors","restriction":"Errors"},{"name":"message","doc":null,"default_value":"\"Validation error\"","external_name":"message","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(errors, message)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"errors:Errors-instance-method","html_id":"errors:Errors-instance-method","name":"errors","doc":"Returns `Errors` container (`Hash`).","summary":"

Returns Errors container (Hash).

","abstract":false,"args":[],"args_string":" : Errors","args_html":" : Errors","location":{"filename":"src/check.cr","line_number":29,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/check.cr#L29"},"def":{"name":"errors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Errors","visibility":"Public","body":"@errors"}}],"macros":[],"types":[]}]},{"html_id":"validator/Valid","path":"Valid.html","kind":"alias","full_name":"Valid","name":"Valid","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validator.cr#L124"}],"repository_name":"validator","program":false,"enum":false,"alias":true,"aliased":"Validator","aliased_html":"Validator","const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Alias of `Validator`","summary":"

Alias of Validator

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"validator/Validator","path":"Validator.html","kind":"module","full_name":"Validator","name":"Validator","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/validator.cr","line_number":116,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validator.cr#L116"},{"filename":"src/validators/alpha_num.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/alpha_num.cr#L8"},{"filename":"src/validators/case_sensitive.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/case_sensitive.cr#L8"},{"filename":"src/validators/comparisons.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L8"},{"filename":"src/validators/format.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L8"},{"filename":"src/validators/geo.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L8"},{"filename":"src/validators/presence.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L8"},{"filename":"src/validators/uri.cr","line_number":8,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L8"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"VERSION","name":"VERSION","value":"{{ (`shards version \\\"/media/data/lab/dev/work/projects/nicolab/crystal/crystal-validator/src\\\"`).chomp.stringify.downcase }}","doc":null,"summary":null}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"∠(・.-)―〉 →◎ `validator` is a [Crystal](https://crystal-lang.org) data validation module.\nVery simple and efficient, all validations return `true` or `false`.\n\nAlso [validator/check](https://nicolab.github.io/crystal-validator/Check.html)\n(not exposed by default) provides error message handling intended for the end user.\n\nThere are 2 main ways to use *validator*:\n\n- As a simple validator to check rules (eg: email, url, min, max, presence, in, ...) which return a boolean.\n- As a more advanced validation system which will check a series of rules\n and returns all validation errors encountered with custom or standard messages.\n\nBy default the **validator** module expose only `Validator` and `Valid` (alias) in the scope:\n\n```\nrequire \"validator\"\n\nValid.email? \"contact@example.org\" # => true\nValid.url? \"https://github.com/Nicolab/crystal-validator\" # => true\nValid.my_validator? \"value to validate\", \"hello\", 42 # => true\n```\n\nAn (optional) expressive validation flavor, `is` available as an alternative. \\\nNot exposed by default, it must be imported:\n\n```\nrequire \"validator/is\"\n\nis :email?, \"contact@example.org\" # => true\nis :url?, \"https://github.com/Nicolab/crystal-validator\" # => true\nis :my_validator?, \"value to validate\", \"hello\", 42 # => true\n\n# raises an error if the email is not valid\nis! :email?, \"contact@@example..org\" # => Validator::Error\n```\n\n`is` is a macro, no overhead during the runtime 🚀\n By the nature of the macros, you can't pass the *validator* name dynamically\n with a variable like that `is(validator_name, \"my value to validate\", arg)`.\n But of course you can pass arguments with variables `is(:validator_name?, arg1, arg2)`.\n\n\n## Check\n\nMake a series of checks, with a customized error message for each case.\n\n```\nrequire \"validator/check\"\n\ncheck = Check.new\n\ncheck(\"email\", \"The email is required.\", is :absence?, \"email\", user)\n```\n## Custom validator\n\nJust add your own method to register a custom *validator* or to overload an existing *validator*.\n\n```\nmodule Validator\n # My custom validator\n def self.my_validator?(value, arg : String, another_arg : Int32) : Bool\n # write here the logic of your validator...\n return true\n end\nend\n\n# Call it\nputs Valid.my_validator?(\"value to validate\", \"hello\", 42) # => true\n\n# or with the `is` flavor\nputs is :my_validator?, \"value to validate\", \"hello\", 42 # => true\n```\n\n`Check` is a simple and lightweight wrapper, let your imagination run wild to add your logic around it.\n\nUsing the custom validator with the validation rules:\n\n```\nrequire \"validator/check\"\n\nclass Article\n # Mixin\n Check.checkable\n\n property title : String\n property content : String\n\n Check.rules(\n content: {\n # Now the custom validator is available\n check: {\n my_validator: {\"My validator error message\"},\n between: {\"The article content must be between 10 and 20 000 characters\", 10, 20_000},\n # ...\n },\n },\n )\nend\n\n# Triggered with all data\nv, article = Article.check(input_data)\n\n# Triggered with one value\nv, content = Article.check_content(input_data[\"content\"]?)\n```","summary":"

∠(・.-)―〉 →◎ validator is a Crystal data validation module.

","class_methods":[{"id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"absence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":47,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L47"},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"absence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"absence?","doc":"Validates the absence of the value.\n- See also `#not_in?`.\n- See also `#empty?`.","summary":"

Validates the absence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":42,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L42"},"def":{"name":"absence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.empty?(list[key]?)"}},{"id":"accepted?(value:String):Bool-class-method","html_id":"accepted?(value:String):Bool-class-method","name":"accepted?","doc":"Validates that the *value* `String` is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n- See also `#refused?`.","summary":"

Validates that the value String is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":180,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L180"},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"])"}},{"id":"accepted?(value):Bool-class-method","html_id":"accepted?(value):Bool-class-method","name":"accepted?","doc":"Validates that the *value* is the representation of an acceptance.\n> One of: \"yes\", \"y\", \"on\", \"o\", \"ok\", \"1\", \"true\"\n\n*value* must implements *#to_s* method.\n- See also `#refused?`.","summary":"

Validates that the value is the representation of an acceptance.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":189,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L189"},"def":{"name":"accepted?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.accepted?(value.to_s)"}},{"id":"ascii_only?(value:String):Bool-class-method","html_id":"ascii_only?(value:String):Bool-class-method","name":"ascii_only?","doc":"Validates that the *value* `String`\nis comprised in its entirety by ASCII characters.","summary":"

Validates that the value String is comprised in its entirety by ASCII characters.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":41,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L41"},"def":{"name":"ascii_only?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ascii_only?"}},{"id":"ascii_only?(values:Array(String)):Bool-class-method","html_id":"ascii_only?(values:Array(String)):Bool-class-method","name":"ascii_only?","doc":"Validates that all the `String` in the *values* `Array`\nare comprised in their entirety by ASCII characters.","summary":"

Validates that all the String in the values Array are comprised in their entirety by ASCII characters.

","abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"args_string":"(values : Array(String)) : Bool","args_html":"(values : Array(String)) : Bool","location":{"filename":"src/validators/format.cr","line_number":47,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L47"},"def":{"name":"ascii_only?","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nwhile size\n size = size - 1\n if value.ascii_only?(values[i])\n else\n return false\n end\nend\ntrue\n"}},{"id":"base64?(value:String):Bool-class-method","html_id":"base64?(value:String):Bool-class-method","name":"base64?","doc":"Validates that the *value* has the format *base64*.","summary":"

Validates that the value has the format base64.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":87,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L87"},"def":{"name":"base64?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (value.match(@@rx_base64)) && ((value.size % 4) === 0)\n return true\nend\nfalse\n"}},{"id":"between?(value,min,max):Bool-class-method","html_id":"between?(value,min,max):Bool-class-method","name":"between?","doc":"Validates that the *value* is between (inclusive) *min* and *max*.","summary":"

Validates that the value is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, min, max) : Bool","args_html":"(value, min, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":87,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L87"},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min && value <= max"}},{"id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","html_id":"between?(value:String|Array,min:Int,max:Int):Bool-class-method","name":"between?","doc":"Validates that the size of the *value* (`String` or `Array`) is between\n(inclusive) *min* and *max*.\n- See also `#size?`.","summary":"

Validates that the size of the value (String or Array) is between (inclusive) min and max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, min : Int, max : Int) : Bool","args_html":"(value : String | Array, min : Int, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":94,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L94"},"def":{"name":"between?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nsize >= min && size <= max\n"}},{"id":"domain?(value:String):Bool-class-method","html_id":"domain?(value:String):Bool-class-method","name":"domain?","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":23,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L23"},"def":{"name":"domain?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 75 || size < 4\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif m = value.match(@@rx_domain)\nelse\n return false\nend\next_size = m[\"ext\"].size\nif ext_size < 2 || ext_size > 12\n return false\nend\ntrue\n"}},{"id":"email?(value:String):Bool-class-method","html_id":"email?(value:String):Bool-class-method","name":"email?","doc":"Validates that the *value* is an email.\nThis method is stricter than the standard allows.\nIt is subjectively based on the common addresses\nof organisations (@enterprise.ltd, ...)\nand mail services suck as Gmail, Hotmail, Yahoo !, ...","summary":"

Validates that the value is an email.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":158,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L158"},"def":{"name":"email?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif size > 60 || size < 7\n return false\nend\nif value.includes?(\"..\")\n return false\nend\nif value.includes?(\"--\")\n return false\nend\nif value.includes?(\"___\")\n return false\nend\nif m = value.match(@@rx_email)\nelse\n return false\nend\nself.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\n"}},{"id":"empty?(value):Bool-class-method","html_id":"empty?(value):Bool-class-method","name":"empty?","doc":"Validates that the *value* is empty.\n- See also `#absence?`.\n- See also `#not_in?`.","summary":"

Validates that the value is empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":58,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L58"},"def":{"name":"empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"case value\nwhen .nil?\n true\nwhen .is_a?(String)\n value.presence.nil?\nwhen .is_a?(Number)\n value == 0\nwhen .responds_to?(:size)\n value.size == 0\nelse\n false\nend"}},{"id":"ends?(value:String,search:String):Bool-class-method","html_id":"ends?(value:String,search:String):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":243,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L243"},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Char):Bool-class-method","html_id":"ends?(value:String,search:Char):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":248,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L248"},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"ends?(value:String,search:Regex):Bool-class-method","html_id":"ends?(value:String,search:Regex):Bool-class-method","name":"ends?","doc":"Validates that the `String` *value* ends with *search*.\n- See also `#starts?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value ends with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":253,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L253"},"def":{"name":"ends?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.ends_with?(search)"}},{"id":"eq?(value,another_value):Bool-class-method","html_id":"eq?(value,another_value):Bool-class-method","name":"eq?","doc":"Validates that the *value* is equal to *another_value*.","summary":"

Validates that the value is equal to another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":10,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L10"},"def":{"name":"eq?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value == another_value"}},{"id":"gt?(value,another_value):Bool-class-method","html_id":"gt?(value,another_value):Bool-class-method","name":"gt?","doc":"Validates that the *value* is greater than *another_value*.","summary":"

Validates that the value is greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":15,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L15"},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value > another_value"}},{"id":"gt?(value:String|Array,limit:Int):Bool-class-method","html_id":"gt?(value:String|Array,limit:Int):Bool-class-method","name":"gt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *limit* number.","summary":"

Validates that the size of the value (String or Array) is greater than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":21,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L21"},"def":{"name":"gt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size > limit"}},{"id":"gte?(value,another_value):Bool-class-method","html_id":"gte?(value,another_value):Bool-class-method","name":"gte?","doc":"Validates that the *value* is equal to or greater than *another_value*.\n> Similar to `#min`.","summary":"

Validates that the value is equal to or greater than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":27,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L27"},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= another_value"}},{"id":"gte?(value:String|Array,min:Int):Bool-class-method","html_id":"gte?(value:String|Array,min:Int):Bool-class-method","name":"gte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis greater than *min* number.\n> Similar to `#min`.","summary":"

Validates that the size of the value (String or Array) is greater than min number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":34,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L34"},"def":{"name":"gte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"hex?(value:String):Bool-class-method","html_id":"hex?(value:String):Bool-class-method","name":"hex?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal string.","summary":"

Validates that the String value does denote a representation of a hexadecimal string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":112,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L112"},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex).nil?"}},{"id":"hex?(value:Bytes):Bool-class-method","html_id":"hex?(value:Bytes):Bool-class-method","name":"hex?","doc":"Validates that the `Bytes` *value* does denote\na representation of a hexadecimal slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a hexadecimal slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":118,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L118"},"def":{"name":"hex?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(String.new(value)).match(@@rx_hex).nil?"}},{"id":"hex_color?(value:String):Bool-class-method","html_id":"hex_color?(value:String):Bool-class-method","name":"hex_color?","doc":"Validates that the `String` *value* does denote\na representation of a hexadecimal color.\n\n```\nValid.hex_color? \"#fff\" => true\nValid.hex_color? \"#ffffff\" => true\n```","summary":"

Validates that the String value does denote a representation of a hexadecimal color.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":129,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L129"},"def":{"name":"hex_color?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_hex_color).nil?"}},{"id":"in?(value,list:Array):Bool-class-method","html_id":"in?(value,list:Array):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":109,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L109"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value:String,str:String):Bool-class-method","html_id":"in?(value:String,str:String):Bool-class-method","name":"in?","doc":"Validates that the (*str*) `String` contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (str) String contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":101,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L101"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"str.includes?(value)"}},{"id":"in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"in?(key:Symbol|String,list:Hash):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":129,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L129"},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":124,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L124"},"def":{"name":"in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.has_key?(key)"}},{"id":"in?(value,list:Range):Bool-class-method","html_id":"in?(value,list:Range):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":119,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L119"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"in?(value,list:Tuple):Bool-class-method","html_id":"in?(value,list:Tuple):Bool-class-method","name":"in?","doc":"Validates that the (*list*) contains the *value*.\n- See also `#presence?`.\n- See also `#not_in?`.\n- See also `#not_empty?`.","summary":"

Validates that the (list) contains the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":114,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L114"},"def":{"name":"in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"list.includes?(value)"}},{"id":"ip?(value:String):Bool-class-method","html_id":"ip?(value:String):Bool-class-method","name":"ip?","doc":"Validates that the *value* is an IP (IPv4 or IPv6).","summary":"

Validates that the value is an IP (IPv4 or IPv6).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":77,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L77"},"def":{"name":"ip?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.ipv4?(value)) || (self.ipv6?(value))"}},{"id":"ipv4?(value:String):Bool-class-method","html_id":"ipv4?(value:String):Bool-class-method","name":"ipv4?","doc":"Validates that the *value* is an IPv4.","summary":"

Validates that the value is an IPv4.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L82"},"def":{"name":"ipv4?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_ipv4).nil?"}},{"id":"ipv6?(value:String):Bool-class-method","html_id":"ipv6?(value:String):Bool-class-method","name":"ipv6?","doc":"Validates that the *value* is an IPv6.","summary":"

Validates that the value is an IPv6.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":87,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L87"},"def":{"name":"ipv6?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"addr_and_zone = [value]\nif value.includes?('%')\n addr_and_zone = value.split('%')\n if addr_and_zone.size == 2\n else\n return false\n end\n if addr_and_zone[0].includes?(':')\n else\n return false\n end\n if addr_and_zone[1] == \"\"\n return false\n end\nend\nblocks = addr_and_zone[0].split(':')\nfound_omission_block = false\nfound_ipv4_transition_block = self.ipv4?(blocks[blocks.size - 1])\nexpected_number_of_blocks = found_ipv4_transition_block ? 7 : 8\nif blocks.size > expected_number_of_blocks\n return false\nend\nif value == \"::\"\n return true\nend\nif value[0...2] == \"::\"\n blocks.shift(2)\n found_omission_block = true\nelse\n if value[(value.size - 2)..] == \"::\"\n blocks.pop(2)\n found_omission_block = true\n end\nend\ni = 0\nwhile i < blocks.size\n if ((blocks[i] === \"\") && i > 0) && i < (blocks.size - 1)\n if found_omission_block\n return false\n end\n found_omission_block = true\n else\n if (!(found_ipv4_transition_block && (i == (blocks.size - 1)))) && blocks[i].match(@@rx_ipv6_block).nil?\n return false\n end\n end\n i = i + 1\nend\nif found_omission_block\n return blocks.size >= 1\nend\nblocks.size == expected_number_of_blocks\n"}},{"id":"json?(value:String,strict:Bool=true):Bool-class-method","html_id":"json?(value:String,strict:Bool=true):Bool-class-method","name":"json?","doc":"Validates that the *value* represents a JSON string.\n*strict* to `true` (default) to try to parse the JSON,\nreturns `false` if the parsing fails.\nIf *strict* is `false`, only the first char and the last char are checked.","summary":"

Validates that the value represents a JSON string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"args_string":"(value : String, strict : Bool = true) : Bool","args_html":"(value : String, strict : Bool = true) : Bool","location":{"filename":"src/validators/format.cr","line_number":64,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L64"},"def":{"name":"json?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"strict","doc":null,"default_value":"true","external_name":"strict","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if strict\n begin\n JSON.parse(value)\n rescue err\n return false\n else\n return true\n end\nend\n((self.starts?(value, \"{\")) && (self.ends?(value, \"}\"))) || ((self.starts?(value, \"[\")) && (self.ends?(value, \"]\")))\n"}},{"id":"jwt?(value:String):Bool-class-method","html_id":"jwt?(value:String):Bool-class-method","name":"jwt?","doc":"Validates that the *value* is a *JSON Web Token*.","summary":"

Validates that the value is a JSON Web Token.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":95,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L95"},"def":{"name":"jwt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_jwt).nil?"}},{"id":"lat?(value:String|Float):Bool-class-method","html_id":"lat?(value:String|Float):Bool-class-method","name":"lat?","doc":"Validates that the *value* is a valid format representation of a geographical latitude.\n- See also `#lng?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical latitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":31,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L31"},"def":{"name":"lat?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lat).nil?"}},{"id":"lat_lng?(value:String):Bool-class-method","html_id":"lat_lng?(value:String):Bool-class-method","name":"lat_lng?","doc":"Validates that the *value* is a valid format representation of\na geographical position (given in latitude and longitude).\n- See also `#lat?`.\n- See also `#lng?`.","summary":"

Validates that the value is a valid format representation of a geographical position (given in latitude and longitude).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/geo.cr","line_number":16,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L16"},"def":{"name":"lat_lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if !(value.includes?(\",\"))\n return false\nend\nlat, lng = value.split(\",\")\nif lat && lng\nelse\n return false\nend\nif ((lat.starts_with?('(')) && (!(lng.ends_with?(')'))))\n return false\nend\nif ((lng.ends_with?(')')) && (!(lat.starts_with?('('))))\n return false\nend\nif (lat.match(@@rx_geo_lat)) && (lng.match(@@rx_geo_lng))\n return true\nend\nfalse\n"}},{"id":"lng?(value:String|Float):Bool-class-method","html_id":"lng?(value:String|Float):Bool-class-method","name":"lng?","doc":"Validates that the *value* is a valid format representation of a geographical longitude.\n- See also `#lat?`.\n- See also `#lat_lng?`.","summary":"

Validates that the value is a valid format representation of a geographical longitude.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"args_string":"(value : String | Float) : Bool","args_html":"(value : String | Float) : Bool","location":{"filename":"src/validators/geo.cr","line_number":38,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/geo.cr#L38"},"def":{"name":"lng?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Float"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(@@rx_geo_lng).nil?"}},{"id":"lower?(value:String):Bool-class-method","html_id":"lower?(value:String):Bool-class-method","name":"lower?","doc":"Validates that the *value* is in lower case.","summary":"

Validates that the value is in lower case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":10,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/case_sensitive.cr#L10"},"def":{"name":"lower?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.downcase === value)"}},{"id":"lt?(value:String|Array,limit:Int):Bool-class-method","html_id":"lt?(value:String|Array,limit:Int):Bool-class-method","name":"lt?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis lesser than *limit* number.","summary":"

Validates that the size of the value (String or Array) is lesser than limit number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"args_string":"(value : String | Array, limit : Int) : Bool","args_html":"(value : String | Array, limit : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":45,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L45"},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"limit","doc":null,"default_value":"","external_name":"limit","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size < limit"}},{"id":"lt?(value,another_value):Bool-class-method","html_id":"lt?(value,another_value):Bool-class-method","name":"lt?","doc":"Validates that the *value* is lesser than *another_value*.","summary":"

Validates that the value is lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":39,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L39"},"def":{"name":"lt?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value < another_value"}},{"id":"lte?(value:String|Array,max:Int):Bool-class-method","html_id":"lte?(value:String|Array,max:Int):Bool-class-method","name":"lte?","doc":"Validates that the size of the *value* (`String` or `Array`)\nis equal or lesser than *max* number.\n> Similar to `#max`.","summary":"

Validates that the size of the value (String or Array) is equal or lesser than max number.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":58,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L58"},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"lte?(value,another_value):Bool-class-method","html_id":"lte?(value,another_value):Bool-class-method","name":"lte?","doc":"Validates that the *value* is equal to or lesser than *another_value*.\n> Similar to `#max`.","summary":"

Validates that the value is equal to or lesser than another_value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"args_string":"(value, another_value) : Bool","args_html":"(value, another_value) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":51,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L51"},"def":{"name":"lte?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"another_value","doc":null,"default_value":"","external_name":"another_value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= another_value"}},{"id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","html_id":"mac_addr?(value:String,no_colons:Bool=false):Bool-class-method","name":"mac_addr?","doc":"Validates that the *value* is a MAC address.","summary":"

Validates that the value is a MAC address.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"args_string":"(value : String, no_colons : Bool = false) : Bool","args_html":"(value : String, no_colons : Bool = false) : Bool","location":{"filename":"src/validators/uri.cr","line_number":176,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L176"},"def":{"name":"mac_addr?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"no_colons","doc":null,"default_value":"false","external_name":"no_colons","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if no_colons\n return !value.match(@@rx_mac_addr_no_colons).nil?\nend\n(((!value.match(@@rx_mac_addr).nil?) || (!value.match(@@rx_mac_addr_with_hyphen).nil?)) || (!value.match(@@rx_mac_addr_with_spaces).nil?)) || (!value.match(@@rx_mac_addr_with_dots).nil?)\n"}},{"id":"magnet_uri?(value:String):Bool-class-method","html_id":"magnet_uri?(value:String):Bool-class-method","name":"magnet_uri?","doc":"Validates that the *value* is a Magnet URI.","summary":"

Validates that the value is a Magnet URI.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":186,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L186"},"def":{"name":"magnet_uri?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_magnet_uri).nil?"}},{"id":"match?(value:Number,pattern:Regex):Bool-class-method","html_id":"match?(value:Number,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : Number, pattern : Regex) : Bool","args_html":"(value : Number, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":15,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L15"},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Number"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.to_s.match(pattern).nil?"}},{"id":"match?(value:String,pattern:Regex):Bool-class-method","html_id":"match?(value:String,pattern:Regex):Bool-class-method","name":"match?","doc":"Validates that the *value* matches the *pattern*.","summary":"

Validates that the value matches the pattern.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"args_string":"(value : String, pattern : Regex) : Bool","args_html":"(value : String, pattern : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":10,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L10"},"def":{"name":"match?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"pattern","doc":null,"default_value":"","external_name":"pattern","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(pattern).nil?"}},{"id":"max?(value,max):Bool-class-method","html_id":"max?(value,max):Bool-class-method","name":"max?","doc":"Validates that the *value* is equal to or lesser than *max* (inclusive).\n> Similar to `#lte`.","summary":"

Validates that the value is equal to or lesser than max (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"args_string":"(value, max) : Bool","args_html":"(value, max) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":76,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L76"},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value <= max"}},{"id":"max?(value:String|Array,max:Int):Bool-class-method","html_id":"max?(value:String|Array,max:Int):Bool-class-method","name":"max?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"args_string":"(value : String | Array, max : Int) : Bool","args_html":"(value : String | Array, max : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L82"},"def":{"name":"max?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"max","doc":null,"default_value":"","external_name":"max","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size <= max"}},{"id":"md5?(value:String):Bool-class-method","html_id":"md5?(value:String):Bool-class-method","name":"md5?","doc":"Validates that the *value* has the format *md5*.","summary":"

Validates that the value has the format md5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L82"},"def":{"name":"md5?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(@@rx_md5).nil?"}},{"id":"min?(value,min):Bool-class-method","html_id":"min?(value,min):Bool-class-method","name":"min?","doc":"Validates that the *value* is equal to or greater than *min* (inclusive).\n> Similar to `#gte`.","summary":"

Validates that the value is equal to or greater than min (inclusive).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"args_string":"(value, min) : Bool","args_html":"(value, min) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":64,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L64"},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value >= min"}},{"id":"min?(value:String|Array,min:Int):Bool-class-method","html_id":"min?(value:String|Array,min:Int):Bool-class-method","name":"min?","doc":":ditto:\n> Based on the size of the `String`.","summary":"

:ditto: > Based on the size of the String.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"args_string":"(value : String | Array, min : Int) : Bool","args_html":"(value : String | Array, min : Int) : Bool","location":{"filename":"src/validators/comparisons.cr","line_number":70,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L70"},"def":{"name":"min?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String | Array"},{"name":"min","doc":null,"default_value":"","external_name":"min","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.size >= min"}},{"id":"mongo_id?(value:Bytes):Bool-class-method","html_id":"mongo_id?(value:Bytes):Bool-class-method","name":"mongo_id?","doc":"Validates that the `Bytes` *value* does denote\na representation of a *MongoID* slice of Bytes.","summary":"

Validates that the Bytes value does denote a representation of a MongoID slice of Bytes.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"args_string":"(value : Bytes) : Bool","args_html":"(value : Bytes) : Bool","location":{"filename":"src/validators/format.cr","line_number":143,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L143"},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"mongo_id?(value:String):Bool-class-method","html_id":"mongo_id?(value:String):Bool-class-method","name":"mongo_id?","doc":"Validates that the `String` *value* does denote\na representation of a *MongoID* string.","summary":"

Validates that the String value does denote a representation of a MongoID string.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":137,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L137"},"def":{"name":"mongo_id?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.hex?(value)) && (value.size == 24)"}},{"id":"not_empty?(value):Bool-class-method","html_id":"not_empty?(value):Bool-class-method","name":"not_empty?","doc":"Validates that the *value* is not empty.\n- See also `#presence?`.\n- See also `#in?`.","summary":"

Validates that the value is not empty.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":71,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L71"},"def":{"name":"not_empty?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(self.empty?(value)) == false"}},{"id":"not_in?(value:String,str:String):Bool-class-method","html_id":"not_in?(value:String,str:String):Bool-class-method","name":"not_in?","doc":"Validates that the (*str*) `String` does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (str) String does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"args_string":"(value : String, str : String) : Bool","args_html":"(value : String, str : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":141,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L141"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"str","doc":null,"default_value":"","external_name":"str","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(str.includes?(value))"}},{"id":"not_in?(value,list:Array):Bool-class-method","html_id":"not_in?(value,list:Array):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"args_string":"(value, list : Array) : Bool","args_html":"(value, list : Array) : Bool","location":{"filename":"src/validators/presence.cr","line_number":149,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L149"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Array"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Tuple):Bool-class-method","html_id":"not_in?(value,list:Tuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"args_string":"(value, list : Tuple) : Bool","args_html":"(value, list : Tuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":154,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L154"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Tuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(value,list:Range):Bool-class-method","html_id":"not_in?(value,list:Range):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"args_string":"(value, list : Range) : Bool","args_html":"(value, list : Range) : Bool","location":{"filename":"src/validators/presence.cr","line_number":159,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L159"},"def":{"name":"not_in?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.includes?(value))"}},{"id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:NamedTuple):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : Symbol | String, list : NamedTuple) : Bool","args_html":"(key : Symbol | String, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":164,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L164"},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","html_id":"not_in?(key:Symbol|String,list:Hash):Bool-class-method","name":"not_in?","doc":"Validates that the (*list*) does not contain the *value*.\n- See also `#absence?`.\n- See also `#in?`.\n- See also `#empty?`.","summary":"

Validates that the (list) does not contain the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : Symbol | String, list : Hash) : Bool","args_html":"(key : Symbol | String, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":169,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L169"},"def":{"name":"not_in?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"Symbol | String"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!(list.has_key?(key))"}},{"id":"not_null?(value):Bool-class-method","html_id":"not_null?(value):Bool-class-method","name":"not_null?","doc":"Validates that the *value* is not null (`nil`).\n- See also `#null?`.\n- See also `#not_empty?`.","summary":"

Validates that the value is not null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":89,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L89"},"def":{"name":"not_null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.nil?"}},{"id":"null?(value):Bool-class-method","html_id":"null?(value):Bool-class-method","name":"null?","doc":"Validates that the *value* is null (`nil`).\n- See also `#empty?`.\n- See also `#not_null?`.","summary":"

Validates that the value is null (nil).

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":82,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L82"},"def":{"name":"null?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.nil?"}},{"id":"number?(value:String):Bool-class-method","html_id":"number?(value:String):Bool-class-method","name":"number?","doc":"Validates that the *value* is a numeric `String` representation.","summary":"

Validates that the value is a numeric String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/alpha_num.cr","line_number":12,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/alpha_num.cr#L12"},"def":{"name":"number?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_number).nil?)"}},{"id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","html_id":"port?(value:String="0",min:String="1",max:String="65535"):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"args_string":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","args_html":"(value : String = "0", min : String = "1", max : String = "65535") : Bool","location":{"filename":"src/validators/uri.cr","line_number":44,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L44"},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"\"0\"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"\"1\"","external_name":"min","restriction":"String"},{"name":"max","doc":null,"default_value":"\"65535\"","external_name":"max","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if (self.number?(min)) && (self.number?(max))\nelse\n return false\nend\nself.port?(value.to_i, min.to_i, max.to_i)\n"}},{"id":"port?(value=0,min=1,max=65535):Bool-class-method","html_id":"port?(value=0,min=1,max=65535):Bool-class-method","name":"port?","doc":"Validates that the *value* is in a valid port range,\nbetween (inclusive) 1 / *min* and 65535 / *max*.","summary":"

Validates that the value is in a valid port range, between (inclusive) 1 / min and 65535 / max.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"args_string":"(value = 0, min = 1, max = 65535) : Bool","args_html":"(value = 0, min = 1, max = 65535) : Bool","location":{"filename":"src/validators/uri.cr","line_number":38,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L38"},"def":{"name":"port?","args":[{"name":"value","doc":null,"default_value":"0","external_name":"value","restriction":""},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"65535","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if self.between?(value, 1, 65535)\nelse\n return false\nend\nself.between?(value, min, max)\n"}},{"id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","html_id":"presence?(key:String|Symbol,list:NamedTuple):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"args_string":"(key : String | Symbol, list : NamedTuple) : Bool","args_html":"(key : String | Symbol, list : NamedTuple) : Bool","location":{"filename":"src/validators/presence.cr","line_number":31,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L31"},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"NamedTuple"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","html_id":"presence?(key:String|Symbol|Number,list:Hash):Bool-class-method","name":"presence?","doc":"Validates the presence of the value.\n- See also `#in?`.\n- See also `#not_empty?`.","summary":"

Validates the presence of the value.

","abstract":false,"args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"args_string":"(key : String | Symbol | Number, list : Hash) : Bool","args_html":"(key : String | Symbol | Number, list : Hash) : Bool","location":{"filename":"src/validators/presence.cr","line_number":26,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L26"},"def":{"name":"presence?","args":[{"name":"key","doc":null,"default_value":"","external_name":"key","restriction":"String | Symbol | Number"},{"name":"list","doc":null,"default_value":"","external_name":"list","restriction":"Hash"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.not_empty?(list[key]?)"}},{"id":"refused?(value):Bool-class-method","html_id":"refused?(value):Bool-class-method","name":"refused?","doc":"Returns `true` if the *value* is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n\n*value* must implements *#to_s* method.\n- See also `#accepted?`.","summary":"

Returns true if the value is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value) : Bool","args_html":"(value) : Bool","location":{"filename":"src/validators/presence.cr","line_number":209,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L209"},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.refused?(value.to_s)"}},{"id":"refused?(value:String):Bool-class-method","html_id":"refused?(value:String):Bool-class-method","name":"refused?","doc":"Validates that the *value* `String` is the representation of a refusal.\n> One of: \"no\", \"n\", \"off\", \"0\", \"false\"\n- See also `#accepted?`.","summary":"

Validates that the value String is the representation of a refusal.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":200,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L200"},"def":{"name":"refused?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"self.in?(value.downcase, [\"no\", \"n\", \"off\", \"0\", \"false\"])"}},{"id":"size?(value,size:Array(String))-class-method","html_id":"size?(value,size:Array(String))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"args_string":"(value, size : Array(String))","args_html":"(value, size : Array(String))","location":{"filename":"src/validators/comparisons.cr","line_number":122,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L122"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(String)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size.to_s)"}},{"id":"size?(value,size:Array(Int))-class-method","html_id":"size?(value,size:Array(Int))-class-method","name":"size?","doc":"Validates that the *value* is in the *size* array.\n- See also `#between?`.","summary":"

Validates that the value is in the size array.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"args_string":"(value, size : Array(Int))","args_html":"(value, size : Array(Int))","location":{"filename":"src/validators/comparisons.cr","line_number":117,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L117"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Array(Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:Range)-class-method","html_id":"size?(value,size:Range)-class-method","name":"size?","doc":"Validates that the *value* is in the *size* range.\n- See also `#between?`.","summary":"

Validates that the value is in the size range.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"args_string":"(value, size : Range)","args_html":"(value, size : Range)","location":{"filename":"src/validators/comparisons.cr","line_number":111,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L111"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size.includes?(value.size)"}},{"id":"size?(value,size:String)-class-method","html_id":"size?(value,size:String)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"args_string":"(value, size : String)","args_html":"(value, size : String)","location":{"filename":"src/validators/comparisons.cr","line_number":105,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L105"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size.to_s == size"}},{"id":"size?(value,size:Int)-class-method","html_id":"size?(value,size:Int)-class-method","name":"size?","doc":"Validates that the *value* is equal to the *size*.","summary":"

Validates that the value is equal to the size.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"args_string":"(value, size : Int)","args_html":"(value, size : Int)","location":{"filename":"src/validators/comparisons.cr","line_number":100,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/comparisons.cr#L100"},"def":{"name":"size?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""},{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"value.size == size"}},{"id":"slug?(value:String,min=1,max=100):Bool-class-method","html_id":"slug?(value:String,min=1,max=100):Bool-class-method","name":"slug?","doc":"Validates that the *value* is a slug.","summary":"

Validates that the value is a slug.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"args_string":"(value : String, min = 1, max = 100) : Bool","args_html":"(value : String, min = 1, max = 100) : Bool","location":{"filename":"src/validators/uri.cr","line_number":171,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L171"},"def":{"name":"slug?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"min","doc":null,"default_value":"1","external_name":"min","restriction":""},{"name":"max","doc":null,"default_value":"100","external_name":"max","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"!value.match(/^([a-zA-Z0-9_-]{#{min},#{max}})$/).nil?"}},{"id":"starts?(value:String,search:Char):Bool-class-method","html_id":"starts?(value:String,search:Char):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"args_string":"(value : String, search : Char) : Bool","args_html":"(value : String, search : Char) : Bool","location":{"filename":"src/validators/presence.cr","line_number":226,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L226"},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Char"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:Regex):Bool-class-method","html_id":"starts?(value:String,search:Regex):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"args_string":"(value : String, search : Regex) : Bool","args_html":"(value : String, search : Regex) : Bool","location":{"filename":"src/validators/presence.cr","line_number":231,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L231"},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"Regex"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"starts?(value:String,search:String):Bool-class-method","html_id":"starts?(value:String,search:String):Bool-class-method","name":"starts?","doc":"Validates that the `String` *value* starts with *search*.\n- See also `#ends?`.\n- See also `#match?`.\n- See also `#in?`.","summary":"

Validates that the String value starts with search.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"args_string":"(value : String, search : String) : Bool","args_html":"(value : String, search : String) : Bool","location":{"filename":"src/validators/presence.cr","line_number":221,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/presence.cr#L221"},"def":{"name":"starts?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"search","doc":null,"default_value":"","external_name":"search","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"value.starts_with?(search)"}},{"id":"time?(value:String):Bool-class-method","html_id":"time?(value:String):Bool-class-method","name":"time?","doc":"Validates that the *value* is a time `String` representation.","summary":"

Validates that the value is a time String representation.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/format.cr","line_number":31,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L31"},"def":{"name":"time?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (!value.match(@@rx_time).nil?)"}},{"id":"upper?(value:String):Bool-class-method","html_id":"upper?(value:String):Bool-class-method","name":"upper?","doc":"Validates that the *value* is in upper case.","summary":"

Validates that the value is in upper case.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/case_sensitive.cr","line_number":15,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/case_sensitive.cr#L15"},"def":{"name":"upper?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"(!value.blank?) && (value.upcase === value)"}},{"id":"url?(value:String):Bool-class-method","html_id":"url?(value:String):Bool-class-method","name":"url?","doc":"Validates that the *value* is a URL.","summary":"

Validates that the value is a URL.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"args_string":"(value : String) : Bool","args_html":"(value : String) : Bool","location":{"filename":"src/validators/uri.cr","line_number":52,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/uri.cr#L52"},"def":{"name":"url?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"size = value.size\nif ((size >= 2083 || size < 11) || (value.match(/[\\s<>]/))) || (value.starts_with?(\"mailto:\"))\n return false\nend\nif m = value.match(@@rx_url)\nelse\n return false\nend\nif self.domain?(\"#{m[\"name\"]}.#{m[\"ext\"]}\")\nelse\n return false\nend\nsp = (value.gsub(/^http(?:s)?:\\/\\//, \"\")).split(\":\")\nif sp.size > 1\n if m_port = sp[1].match(/^[0-9]+/)\n else\n return true\n end\n return self.port?(m_port[0])\nend\ntrue\n"}},{"id":"uuid?(value:String,version=0):Bool-class-method","html_id":"uuid?(value:String,version=0):Bool-class-method","name":"uuid?","doc":"Validates that the *value* is a *UUID*\nVersions: 0 (all), 3, 4 and 5. *version* by default is 0 (all).","summary":"

Validates that the value is a UUID Versions: 0 (all), 3, 4 and 5.

","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"args_string":"(value : String, version = 0) : Bool","args_html":"(value : String, version = 0) : Bool","location":{"filename":"src/validators/format.cr","line_number":103,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validators/format.cr#L103"},"def":{"name":"uuid?","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"String"},{"name":"version","doc":null,"default_value":"0","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"if @@rx_uuid.has_key?(version)\nelse\n return false\nend\n!value.match(@@rx_uuid[version]).nil?\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"validator/Validator/Error","path":"Validator/Error.html","kind":"class","full_name":"Validator::Error","name":"Error","abstract":false,"superclass":{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"validator/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"validator/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"validator/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/validator.cr","line_number":120,"url":"https://github.com/Nicolab/crystal-validator/blob/d97d76fbacd2427338e0178b4c926270338c820e/src/validator.cr#L120"}],"repository_name":"validator","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"validator/Validator","kind":"module","full_name":"Validator","name":"Validator"},"doc":"Used by `is!` when a validation is not `true`.","summary":"

Used by is! when a validation is not true.

","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}) \ No newline at end of file diff --git a/docs/toplevel.html b/docs/toplevel.html index 7adc566..4c9d3ab 100644 --- a/docs/toplevel.html +++ b/docs/toplevel.html @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - Top Level Namespace - validator master-dev + Top Level Namespace - validator master @@ -39,7 +39,7 @@

- master-dev + master @@ -237,6 +237,8 @@


+ [View source] +
@@ -258,6 +260,8 @@


+ [View source] +
diff --git a/shard.yml b/shard.yml index dc2fc01..344ad4e 100644 --- a/shard.yml +++ b/shard.yml @@ -1,11 +1,11 @@ name: validator -version: 1.3.0 +version: 1.4.0 crystal: ">= 0.35.0, < 2.0.0" +license: MIT authors: - Nicolas Talle -license: MIT targets: validator: