Class: HelperValidation
- Inherits:
-
Object
- Object
- HelperValidation
- Defined in:
- lib/util/validation/helper.rb
Class Method Summary collapse
- .is_future_date(expiration_date) ⇒ Object
- .is_valid_card_number(number) ⇒ Object
- .is_valid_email(email) ⇒ Object
- .validate_currency_code(currency_code) ⇒ Object
- .validate_string_start(string, start) ⇒ Object
- .validate_value(value, allowed_values) ⇒ Object
Class Method Details
.is_future_date(expiration_date) ⇒ Object
35 36 37 38 |
# File 'lib/util/validation/helper.rb', line 35 def self.is_future_date(expiration_date) exp_date = Time.at(expiration_date) exp_date > Time.now end |
.is_valid_card_number(number) ⇒ Object
8 9 10 |
# File 'lib/util/validation/helper.rb', line 8 def self.is_valid_card_number(number) !number.match(/^\d{13,19}$/).nil? end |
.is_valid_email(email) ⇒ Object
12 13 14 |
# File 'lib/util/validation/helper.rb', line 12 def self.is_valid_email(email) !email.match(/^\S+@\S+\.\S+$/).nil? end |
.validate_currency_code(currency_code) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/util/validation/helper.rb', line 16 def self.validate_currency_code(currency_code) raise CustomException.new('Currency code is empty.') if currency_code.nil? || currency_code.empty? raise CustomException.new('Currency code must be a string.') unless currency_code.is_a?(String) allowed_values = ['PEN', 'USD'] raise CustomException.new('Currency code must be either "PEN" or "USD".') unless allowed_values.include?(currency_code) end |
.validate_string_start(string, start) ⇒ Object
25 26 27 28 29 |
# File 'lib/util/validation/helper.rb', line 25 def self.validate_string_start(string, start) unless string.start_with?("#{start}_test_") || string.start_with?("#{start}_live_") raise CustomException.new("Incorrect format. The format must start with #{start}_test_ or #{start}_live_") end end |
.validate_value(value, allowed_values) ⇒ Object
31 32 33 |
# File 'lib/util/validation/helper.rb', line 31 def self.validate_value(value, allowed_values) raise CustomException.new("Invalid value. It must be #{JSON.generate(allowed_values)}.") unless allowed_values.include?(value) end |