Module: Securial::Helpers::NormalizingHelper

Extended by:
NormalizingHelper
Included in:
NormalizingHelper
Defined in:
lib/securial/helpers/normalizing_helper.rb

Overview

Provides data normalization methods for common input sanitization.

This module contains methods to normalize various types of user input to ensure data consistency and prevent common formatting issues that could lead to duplicate records or authentication problems.

Instance Method Summary collapse

Instance Method Details

#normalize_email_address(email) ⇒ String

Normalizes an email address for consistent storage and comparison.

Strips whitespace and converts to lowercase to ensure email addresses are stored consistently regardless of how users input them. This prevents duplicate accounts and authentication issues caused by case sensitivity.

Examples:

Standard normalization

normalize_email_address("  [email protected]  ")
# => "[email protected]"

Handling empty input

normalize_email_address("")
# => ""

Preserving valid format

normalize_email_address("[email protected]")
# => "[email protected]"


50
51
52
53
54
# File 'lib/securial/helpers/normalizing_helper.rb', line 50

def normalize_email_address(email)
  return "" if email.empty?

  email.strip.downcase
end

#normalize_role_name(role_name) ⇒ String

Normalizes a role name for consistent display and storage.

Strips whitespace, converts to lowercase, then applies title case formatting to ensure role names are displayed consistently across the application. This helps maintain a professional appearance and prevents formatting issues.

Examples:

Standard normalization

normalize_role_name("  admin user  ")
# => "Admin User"

Handling mixed case input

normalize_role_name("SUPER_ADMIN")
# => "Super Admin"

Handling empty input

normalize_role_name("")
# => ""

Single word roles

normalize_role_name("admin")
# => "Admin"


81
82
83
84
85
# File 'lib/securial/helpers/normalizing_helper.rb', line 81

def normalize_role_name(role_name)
  return "" if role_name.empty?

  role_name.strip.downcase.titleize
end