class Coppertone::IPAddressWrapper
A wrapper class for the IP address of the SMTP client that is emitting the email and is being validated by the SPF process. This class contains a number of helper methods designed to support the use of IPs in mechanism evaluation and macro string evaluation.
Note: This class should only be used with a single IP address, and will fail if passed an address with a non-trivial network prefix
Constants
- IP_PARSE_ERROR
Hack for JRuby - remove when JRuby moves to 2.0.x
Attributes
ip[R]
string_representation[R]
Public Class Methods
new(s)
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 14 def initialize(s) @ip = self.class.parse(s) raise ArgumentError unless @ip @string_representation = s end
normalize_ip(parsed_ip)
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 38 def self.normalize_ip(parsed_ip) return parsed_ip unless parsed_ip&.ipv6? parsed_ip.ipv4_mapped? ? parsed_ip.native : parsed_ip end
parse(s)
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 28 def self.parse(s) return nil unless s return nil if s.index('/') ip_addr = IPAddr.new(s) normalize_ip(ip_addr) rescue IP_PARSE_ERROR nil end
Public Instance Methods
ip_v4()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 62 def ip_v4 original_ipv4? ? @ip : nil end
ip_v6()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 66 def ip_v6 original_ipv6? ? @ip : nil end
original_ipv4?()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 70 def original_ipv4? @ip.ipv4? end
original_ipv6?()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 74 def original_ipv6? @ip.ipv6? end
to_dotted_notation()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 44 def to_dotted_notation if original_ipv6? format('%.32x', @ip.to_i).split(//).join('.').upcase elsif original_ipv4? @ip.to_s end end
Also aliased as: i
to_human_readable()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 53 def to_human_readable @ip.to_s end
Also aliased as: c
to_s()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 78 def to_s @string_representation end
v()
click to toggle source
# File lib/coppertone/ip_address_wrapper.rb, line 58 def v original_ipv4? ? 'in-addr' : 'ip6' end