Module: ValidationsHelper
- Defined in:
- lib/watir_helper/validations_helper.rb
Instance Method Summary collapse
-
#age_data_type_format_msg ⇒ Object
Age data type format message.
-
#arg_invalid_type_msg(arg_pos, data_type_expected) ⇒ Object
Print invalid data type msg.
-
#invalid_date_error_type(err_type, obj_type) ⇒ Object
Invalid date format message.
-
#is_string_contains_another_string?(char_string, char_set) ⇒ Boolean
Check whether a string contains another string or not.
-
#is_string_contains_reg_exp?(char_string, reg_exp) ⇒ Boolean
Check whether a string contains a regular expression or not.
-
#is_valid_data_with_format?(date, reg_ex_date, obj_type) ⇒ Boolean
Data passed is in valid format or not.
-
#is_valid_landline_no?(landline_no) ⇒ Boolean
Landline no.
-
#is_valid_length_of_landline_no?(landline_no) ⇒ Boolean
Valid length of landline no.
-
#is_valid_mobile_no?(mobile_no) ⇒ Boolean
Mobile no.
-
#string_contains_reg_exp?(char_string, reg_exp) ⇒ Boolean
String contains regular expression or not.
-
#valid_age?(age) ⇒ Boolean
Age value is between 1 and 100 or not.
-
#valid_ddmmyyyy_date_format?(date) ⇒ Boolean
Check whether a date is in ddmmyyyy format or not.
-
#valid_email_id?(email_id) ⇒ Boolean
Check whether e-mail adress supplied is valid or not.
-
#valid_indian_landline_number?(landline_no) ⇒ Boolean
Check whether the indian landline number entered is valid or not.
-
#valid_indian_mobile_number?(mobile_no) ⇒ Boolean
Check whether the indian mobile number entered is valid or not.
-
#valid_mmddyyyy_date_format?(date) ⇒ Boolean
Check whether a date is in mmddyyyy format or not.
-
#valid_mobile_no_length?(mobile_no) ⇒ Boolean
Mobile no.
-
#valid_string_and_reg_ex?(char_string, reg_exp) ⇒ Boolean
Valid string and regular expression.
-
#valid_strings?(string1, string2) ⇒ Boolean
Valid strings.
Instance Method Details
#age_data_type_format_msg ⇒ Object
Age data type format message.
97 98 99 100 |
# File 'lib/watir_helper/validations_helper.rb', line 97 def age_data_type_format_msg puts "Age should be an Integer." return false end |
#arg_invalid_type_msg(arg_pos, data_type_expected) ⇒ Object
Print invalid data type msg.
111 112 113 |
# File 'lib/watir_helper/validations_helper.rb', line 111 def arg_invalid_type_msg(arg_pos, data_type_expected) puts "#{arg_pos} argument should be a #{data_type_expected}." end |
#invalid_date_error_type(err_type, obj_type) ⇒ Object
Invalid date format message
9 10 11 12 |
# File 'lib/watir_helper/validations_helper.rb', line 9 def invalid_date_error_type(err_type, obj_type) (err_type == "format") ? (puts "Invalid #{obj_type.downcase} format.") : (puts "#{obj_type} should be a String.") return false end |
#is_string_contains_another_string?(char_string, char_set) ⇒ Boolean
Check whether a string contains another string or not.
For e.g is_string_contains_another_string?(“[email protected]”, “123@g”) will return true and is_string_contains_another_string?(“[email protected]”, “13@g”) will return false
146 147 148 |
# File 'lib/watir_helper/validations_helper.rb', line 146 def is_string_contains_another_string?(char_string, char_set) (valid_strings?(char_string, char_set) == true) ? (char_string.sub(char_set, '**').index('**') ? true : false) : false end |
#is_string_contains_reg_exp?(char_string, reg_exp) ⇒ Boolean
Check whether a string contains a regular expression or not.
For e.g is_string_contains_reg_exp?(“[email protected]”, /^[a-zA-Z0-9._%-]@.[a-zA-Z]{2,4}$/) will return true and is_string_contains_reg_exp?(“ankurgeragmail.com”, /^[a-zA-Z0-9._%-]@.[a-zA-Z]2,4$/) will return false
139 140 141 |
# File 'lib/watir_helper/validations_helper.rb', line 139 def is_string_contains_reg_exp?(char_string, reg_exp) (valid_string_and_reg_ex?(char_string, reg_exp) == true) ? (char_string.sub(reg_exp, '**').index('**') ? true : false) : false end |
#is_valid_data_with_format?(date, reg_ex_date, obj_type) ⇒ Boolean
Data passed is in valid format or not.
20 21 22 |
# File 'lib/watir_helper/validations_helper.rb', line 20 def is_valid_data_with_format?(date, reg_ex_date, obj_type) is_string?(date) ? (string_contains_reg_exp?(date, reg_ex_date) ? invalid_date_error_type("format", obj_type) : true) : invalid_date_error_type("data type", obj_type) end |
#is_valid_landline_no?(landline_no) ⇒ Boolean
Landline no. is valid or not.
82 83 84 |
# File 'lib/watir_helper/validations_helper.rb', line 82 def is_valid_landline_no?(landline_no) is_string?(landline_no) ? is_valid_length_of_landline_no?(landline_no) : (puts "Landline no. should be a String.") end |
#is_valid_length_of_landline_no?(landline_no) ⇒ Boolean
Valid length of landline no. or not.
77 78 79 |
# File 'lib/watir_helper/validations_helper.rb', line 77 def is_valid_length_of_landline_no?(landline_no) (landline_no.to_s.length == 12) ? true : (puts "Landline no. should be of 11 digits(for e.g '0130-1234567').") end |
#is_valid_mobile_no?(mobile_no) ⇒ Boolean
Mobile no. is valid or not.
60 61 62 |
# File 'lib/watir_helper/validations_helper.rb', line 60 def is_valid_mobile_no?(mobile_no) (mobile_no.to_i > 0) ? valid_mobile_no_length?(mobile_no) : false end |
#string_contains_reg_exp?(char_string, reg_exp) ⇒ Boolean
String contains regular expression or not.
15 16 17 |
# File 'lib/watir_helper/validations_helper.rb', line 15 def string_contains_reg_exp?(char_string, reg_exp) (char_string =~ reg_exp).nil? end |
#valid_age?(age) ⇒ Boolean
Age value is between 1 and 100 or not. For e.g valid_age?(100) will return true and valid_age?(“100”) will return false(and print message ‘Age should be an Integer.’) and valid_age?(-100) will return false
106 107 108 |
# File 'lib/watir_helper/validations_helper.rb', line 106 def valid_age?(age) is_integer?(age) ? (age > 0 and age <= 100) : age_data_type_format_msg end |
#valid_ddmmyyyy_date_format?(date) ⇒ Boolean
Check whether a date is in ddmmyyyy format or not.
Valid date format “10/02/2015”, “10-02-2015” and “10.02.2015”. For e.g valid_ddmmyyyy_date_format?(10-02-2015) will return false(and print message ‘Date should be a String.’) and valid_ddmmyyyy_date_format?(“10-02-2015”) will return true and valid_ddmmyyyy_date_format?(“42-10-2015”) will return false(and print message ‘Invalid date format.’)
42 43 44 |
# File 'lib/watir_helper/validations_helper.rb', line 42 def valid_ddmmyyyy_date_format?(date) is_valid_data_with_format?(date, /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$/, "Date") end |
#valid_email_id?(email_id) ⇒ Boolean
Check whether e-mail adress supplied is valid or not.
For e.g valid_email_id?(“[email protected]”) will return true and valid_email_id?(“abc123gmail.com”) will return false(and print message ‘Invalid email format.’)
50 51 52 |
# File 'lib/watir_helper/validations_helper.rb', line 50 def valid_email_id?(email_id) is_valid_data_with_format?(email_id, /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, "Email") end |
#valid_indian_landline_number?(landline_no) ⇒ Boolean
Check whether the indian landline number entered is valid or not. For e.g valid_indian_landline_number?(01303030303) will return false(and print message ‘Landline no. should be a String.’) and valid_indian_landline_number?(‘0130-3030303’) will return true and valid_indian_landline_number?(‘0130-30303030’) will return false(and print message ‘Landline no. should be of 11 digits(for e.g ’0130-1234567’).‘)
92 93 94 |
# File 'lib/watir_helper/validations_helper.rb', line 92 def valid_indian_landline_number?(landline_no) is_valid_landline_no?(landline_no) ? is_valid_data_with_format?(landline_no, /^[0]{1}[1-9]{1}[0-9]{1,3}[\-]{1}[1-9]{1}[0-9]{5,7}$/, "Landline no.") : false end |
#valid_indian_mobile_number?(mobile_no) ⇒ Boolean
Check whether the indian mobile number entered is valid or not.
Here valid means mobile no. will have the prefix 9, 8 or 7. It will not tell whether that number exists or not. For e.g valid_indian_mobile_number?(9123456789) will return false(and print message ‘Mobile no. should be a String.’) puts valid_indian_mobile_number?(“9123456789”) will return true puts valid_indian_mobile_number?(“91234567890”) will return false(and print message ‘Mobile no. should be of 10 digits.’)
72 73 74 |
# File 'lib/watir_helper/validations_helper.rb', line 72 def valid_indian_mobile_number?(mobile_no) is_valid_mobile_no?(mobile_no) ? is_valid_data_with_format?(mobile_no, /^([9]{1}|[8]{1}|[7]{1})([0-9]{9})$/, "Mobile no.") : false end |
#valid_mmddyyyy_date_format?(date) ⇒ Boolean
Check whether a date is in mmddyyyy format or not.
Valid date format “02/10/2015”, “02-10-2015” and “02.10.2015”. For e.g valid_mmddyyyy_date_format?(02-10-2015) will return false(and print message ‘Date should be a String.’) and valid_mmddyyyy_date_format?(“02-10-2015”) will return true and valid_mmddyyyy_date_format?(“22-10-2015”) will return false(and print message ‘Invalid date format.’)
31 32 33 |
# File 'lib/watir_helper/validations_helper.rb', line 31 def valid_mmddyyyy_date_format?(date) is_valid_data_with_format?(date, /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/, "Date") end |
#valid_mobile_no_length?(mobile_no) ⇒ Boolean
Mobile no. is of 10 digits or not.
55 56 57 |
# File 'lib/watir_helper/validations_helper.rb', line 55 def valid_mobile_no_length?(mobile_no) (mobile_no.to_s.length == 10) ? true : (puts "Mobile no. should be of 10 digits.") end |
#valid_string_and_reg_ex?(char_string, reg_exp) ⇒ Boolean
Valid string and regular expression.
116 117 118 119 120 121 122 |
# File 'lib/watir_helper/validations_helper.rb', line 116 def valid_string_and_reg_ex?(char_string, reg_exp) str_flag = is_string?(char_string) regex_flag = is_reg_exp?(reg_exp) arg_invalid_type_msg("First", "String") unless(str_flag) arg_invalid_type_msg("Second", "Regular Expression") unless(regex_flag) str_flag && regex_flag end |
#valid_strings?(string1, string2) ⇒ Boolean
Valid strings.
125 126 127 128 129 130 131 |
# File 'lib/watir_helper/validations_helper.rb', line 125 def valid_strings?(string1, string2) str1_flag = is_string?(string1) str2_flag = is_string?(string2) arg_invalid_type_msg("First", "String") unless(str1_flag) arg_invalid_type_msg("Second", "String") unless(str2_flag) str1_flag && str2_flag end |