Module: DomainExtractor::Validators
- Defined in:
- lib/domain_extractor/validators.rb
Overview
Validators hosts fast checks for excluding unsupported hostnames (e.g. IP addresses).
Constant Summary collapse
- IPV4_SEGMENT =
Frozen regex patterns for zero allocation
'(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)'- IPV4_REGEX =
/\A#{IPV4_SEGMENT}(?:\.#{IPV4_SEGMENT}){3}\z/- IPV6_REGEX =
/\A\[?[0-9a-fA-F:]+\]?\z/- DOT =
Frozen string constants
'.'- COLON =
':'- BRACKET_OPEN =
'['
Class Method Summary collapse
Class Method Details
.ip_address?(host) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/domain_extractor/validators.rb', line 18 def ip_address?(host) return false if host.nil? || host.empty? # Fast path: check for dot or colon before running regex if host.include?(DOT) IPV4_REGEX.match?(host) elsif host.include?(COLON) || host.include?(BRACKET_OPEN) IPV6_REGEX.match?(host) else false end end |