Module: Israeli
- Defined in:
- lib/israeli.rb,
lib/israeli/luhn.rb,
lib/israeli/errors.rb,
lib/israeli/result.rb,
lib/israeli/railtie.rb,
lib/israeli/version.rb,
lib/israeli/sanitizer.rb,
lib/israeli/validators/id.rb,
lib/israeli/validators/phone.rb,
lib/israeli/validators/postal_code.rb,
lib/israeli/validators/bank_account.rb
Overview
Main namespace for the Israeli validators gem.
Provides validation utilities for Israeli identifiers including ID numbers (Mispar Zehut), postal codes, phone numbers, and bank accounts.
Defined Under Namespace
Modules: Luhn, Sanitizer, Validators Classes: BankAccountResult, Error, IdResult, InvalidBankAccountError, InvalidFormatError, InvalidIdError, InvalidPhoneError, InvalidPostalCodeError, PhoneResult, PostalCodeResult, Railtie, Result
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
-
.format_bank_account(value, style: :domestic) ⇒ String?
Formats an Israeli bank account number.
-
.format_id(value) ⇒ String?
Formats an Israeli ID number to standard 9-digit format.
-
.format_phone(value, style: :dashed) ⇒ String?
Formats an Israeli phone number.
-
.format_postal_code(value, style: :compact) ⇒ String?
Formats an Israeli postal code.
-
.parse_bank_account(value) ⇒ Israeli::BankAccountResult
Parses an Israeli bank account and returns a result object.
-
.parse_id(value) ⇒ Israeli::IdResult
Parses an Israeli ID number and returns a result object.
-
.parse_phone(value) ⇒ Israeli::PhoneResult
Parses an Israeli phone number and returns a result object.
-
.parse_postal_code(value) ⇒ Israeli::PostalCodeResult
Parses an Israeli postal code and returns a result object.
-
.phone_type(value) ⇒ Symbol?
Detects the type of phone number.
-
.valid_bank_account!(value, format: :any) ⇒ true
Validates an Israeli bank account, raising an error if invalid.
-
.valid_bank_account?(value, format: :any) ⇒ Boolean
Validates an Israeli bank account number.
-
.valid_id!(value) ⇒ true
Validates an Israeli ID number, raising an error if invalid.
-
.valid_id?(value) ⇒ Boolean
Validates an Israeli ID number (Mispar Zehut).
-
.valid_phone!(value, type: :any) ⇒ true
Validates an Israeli phone number, raising an error if invalid.
-
.valid_phone?(value, type: :any) ⇒ Boolean
Validates an Israeli phone number.
-
.valid_postal_code!(value) ⇒ true
Validates an Israeli postal code, raising an error if invalid.
-
.valid_postal_code?(value) ⇒ Boolean
Validates an Israeli postal code (Mikud).
Class Method Details
.format_bank_account(value, style: :domestic) ⇒ String?
Formats an Israeli bank account number.
121 122 123 |
# File 'lib/israeli.rb', line 121 def format_bank_account(value, style: :domestic) Validators::BankAccount.format(value, style: style) end |
.format_id(value) ⇒ String?
Formats an Israeli ID number to standard 9-digit format.
94 95 96 |
# File 'lib/israeli.rb', line 94 def format_id(value) Validators::Id.format(value) end |
.format_phone(value, style: :dashed) ⇒ String?
Formats an Israeli phone number.
103 104 105 |
# File 'lib/israeli.rb', line 103 def format_phone(value, style: :dashed) Validators::Phone.format(value, style: style) end |
.format_postal_code(value, style: :compact) ⇒ String?
Formats an Israeli postal code.
112 113 114 |
# File 'lib/israeli.rb', line 112 def format_postal_code(value, style: :compact) Validators::PostalCode.format(value, style: style) end |
.parse_bank_account(value) ⇒ Israeli::BankAccountResult
Parses an Israeli bank account and returns a result object.
270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/israeli.rb', line 270 def parse_bank_account(value) valid = Validators::BankAccount.valid?(value) reason = valid ? nil : Validators::BankAccount.invalid_reason(value) detected_format = detect_bank_format(value) if valid BankAccountResult.new( original: value, normalized: normalize_bank_value(value, detected_format), valid: valid, reason: reason, format: detected_format ) end |
.parse_id(value) ⇒ Israeli::IdResult
Parses an Israeli ID number and returns a result object.
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/israeli.rb', line 197 def parse_id(value) digits = Sanitizer.digits_only(value) normalized = digits&.rjust(9, "0") valid = Validators::Id.valid?(value) reason = valid ? nil : Validators::Id.invalid_reason(value) IdResult.new( original: value, normalized: normalized, valid: valid, reason: reason ) end |
.parse_phone(value) ⇒ Israeli::PhoneResult
Parses an Israeli phone number and returns a result object.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/israeli.rb', line 222 def parse_phone(value) normalized = Sanitizer.normalize_phone(value) valid = Validators::Phone.valid?(value) phone_type = Validators::Phone.detect_type(value) reason = valid ? nil : Validators::Phone.invalid_reason(value) PhoneResult.new( original: value, normalized: normalized, valid: valid, reason: reason, type: phone_type ) end |
.parse_postal_code(value) ⇒ Israeli::PostalCodeResult
Parses an Israeli postal code and returns a result object.
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/israeli.rb', line 247 def parse_postal_code(value) digits = Sanitizer.digits_only(value) valid = Validators::PostalCode.valid?(value) reason = valid ? nil : Validators::PostalCode.invalid_reason(value) PostalCodeResult.new( original: value, normalized: digits, valid: valid, reason: reason ) end |
.phone_type(value) ⇒ Symbol?
Detects the type of phone number.
73 74 75 |
# File 'lib/israeli.rb', line 73 def phone_type(value) Validators::Phone.detect_type(value) end |
.valid_bank_account!(value, format: :any) ⇒ true
Validates an Israeli bank account, raising an error if invalid.
173 174 175 176 177 178 |
# File 'lib/israeli.rb', line 173 def valid_bank_account!(value, format: :any) return true if valid_bank_account?(value, format: format) reason = Validators::BankAccount.invalid_reason(value, format: format) raise InvalidBankAccountError.new("Invalid Israeli bank account", reason: reason) end |
.valid_bank_account?(value, format: :any) ⇒ Boolean
Validates an Israeli bank account number.
86 87 88 |
# File 'lib/israeli.rb', line 86 def valid_bank_account?(value, format: :any) Validators::BankAccount.valid?(value, format: format) end |
.valid_id!(value) ⇒ true
Validates an Israeli ID number, raising an error if invalid.
137 138 139 140 141 |
# File 'lib/israeli.rb', line 137 def valid_id!(value) return true if valid_id?(value) raise InvalidIdError.new("Invalid Israeli ID", reason: Validators::Id.invalid_reason(value)) end |
.valid_id?(value) ⇒ Boolean
Validates an Israeli ID number (Mispar Zehut).
35 36 37 |
# File 'lib/israeli.rb', line 35 def valid_id?(value) Validators::Id.valid?(value) end |
.valid_phone!(value, type: :any) ⇒ true
Validates an Israeli phone number, raising an error if invalid.
149 150 151 152 153 154 |
# File 'lib/israeli.rb', line 149 def valid_phone!(value, type: :any) return true if valid_phone?(value, type: type) reason = Validators::Phone.invalid_reason(value, type: type) raise InvalidPhoneError.new("Invalid Israeli phone number", reason: reason) end |
.valid_phone?(value, type: :any) ⇒ Boolean
Validates an Israeli phone number.
61 62 63 |
# File 'lib/israeli.rb', line 61 def valid_phone?(value, type: :any) Validators::Phone.valid?(value, type: type) end |
.valid_postal_code!(value) ⇒ true
Validates an Israeli postal code, raising an error if invalid.
161 162 163 164 165 |
# File 'lib/israeli.rb', line 161 def valid_postal_code!(value) return true if valid_postal_code?(value) raise InvalidPostalCodeError.new("Invalid Israeli postal code", reason: Validators::PostalCode.invalid_reason(value)) end |
.valid_postal_code?(value) ⇒ Boolean
Validates an Israeli postal code (Mikud).
47 48 49 |
# File 'lib/israeli.rb', line 47 def valid_postal_code?(value) Validators::PostalCode.valid?(value) end |