Skip to content

ImmosquareConstants is a comprehensive collection of constants useful for a variety of applications.

Notifications You must be signed in to change notification settings

immosquare/immosquare-constants

Repository files navigation

Immosquare Constants

ImmosquareConstants is a gem that provides a collection of constants useful for real estate applications, including a comprehensive list of global locales mapped to their native language names.

Installation

Add this line to your Gemfile:

gem 'immosquare-constants'

Usage

IP

To get the real public IP address of the machine:

ip = ImmosquareConstants::Ip.get_real_ip
puts "Real IP: #{ip}"

The IP retrieval uses Socket to fall back on a local private IP if it cannot fetch the public IP.

Locale

To retrieve the native language name for a given locale:

locale_name = ImmosquareConstants::Locale.native_name_for_locale(:fr)
puts locale_name
## => Français

Ensure you pass the locale as either a string or a symbol. If the locale isn't present in the list, it will return "Locale not found".

Color

Convert a color name to its hexadecimal value:

color = ImmosquareColors.color_name_to_hex("red")
puts color
## => #ff0000

Regex

email_raw

The email_raw method defines the core email matching pattern used by both the email and email_in_string methods:

regex = ImmosquareConstants::Regex.email_raw
puts regex.source
## => "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}"
  • [A-Z0-9._%+-]+: Matches one or more allowed characters in the local part of the email (before the @), including letters, digits, and common special characters.

  • @: Matches the @ symbol separating the local part from the domain.

  • [A-Z0-9.-]+: Matches one or more allowed characters in the domain name, including letters, digits, dots, and hyphens.

  • \.: Matches a literal dot . separating the domain from the extension.

  • [A-Z]{2,}: Matches a domain extension consisting of at least two letters (e.g., com, org, net, fr).

email

email = "[email protected]"
valid = ImmosquareConstants::Regex.email.match?(email)
puts "Email: #{email} is valid? => #{valid}"
## => Email: [email protected] is valid? => true

To validate an email format using a regular expression:

validates_format_of :email, :with => ImmosquareConstants::Regex.email

Email within a string

To match an email embedded in a string:

text   = "Contact us at [email protected] for more info or <[email protected]"
emails = text.scan(ImmosquareConstants::Regex.email_in_string)
puts emails.inspect
## => ["[email protected]", "[email protected]"]

Contributing

Contributions are very much welcome! If you have enhancements, bug fixes, or other suggestions, please open an issue or submit a pull request on our GitHub repository.

License

This gem is licensed under the terms of the MIT License.

About

ImmosquareConstants is a comprehensive collection of constants useful for a variety of applications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages