Class: UniversalValidators::IpValidator
- Inherits:
-
Object
- Object
- UniversalValidators::IpValidator
- Defined in:
- lib/universal_validators/ip_validator.rb
Instance Method Summary collapse
-
#initialize(ip, mask_presence = false) ⇒ IpValidator
constructor
A new instance of IpValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(ip, mask_presence = false) ⇒ IpValidator
Returns a new instance of IpValidator.
3 4 5 6 |
# File 'lib/universal_validators/ip_validator.rb', line 3 def initialize(ip, mask_presence = false) @ip = ip.to_s @mask_presence = mask_presence end |
Instance Method Details
#valid? ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/universal_validators/ip_validator.rb', line 8 def valid? begin check_format_with_netmask if @mask_presence check_format_without_netmask unless @mask_presence rescue return end @ip.split('.').select { |pair| pair.to_i > 255 }.length == 0 end |