Module: Sisimai::RFC791
- Defined in:
- lib/sisimai/rfc791.rb
Overview
Sisimai::RFC791 is a class related to the Internet host
Class Method Summary collapse
-
.find(argv0) ⇒ Array
Find an IPv4 address from the given string.
-
.is_ipv4address(argv0) ⇒ Bool
Returns 1 if the argument is an IPv4 address.
Class Method Details
.find(argv0) ⇒ Array
Find an IPv4 address from the given string
25 26 27 28 29 30 31 |
# File 'lib/sisimai/rfc791.rb', line 25 def find(argv0) return nil if argv0.to_s.empty? return [] if argv0.size < 7 given = argv0.dup.tr('()[],', ' ').squeeze(' ') return given.split(' ').select { |e| is_ipv4address(e) } end |
.is_ipv4address(argv0) ⇒ Bool
Returns 1 if the argument is an IPv4 address
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sisimai/rfc791.rb', line 9 def is_ipv4address(argv0) return false if argv0.nil? || argv0.size < 7 octet = argv0.split(/[.]/); return false if octet.size != 4 octet.each do |e| # Check each octet is between 0 and 255 return false unless e =~ /\A[0-9]{1,3}\z/; v = e.to_i return false if v < 0 || v > 255 end return true end |