<commit_before># coding: us-ascii

module Net; module IPAddress; class Version4

  # @return [String]
  def to_s
    string_for_octets @octets
  end

  # @return [String]
  # @example
  #   IPAddress.parse('192.168.1.1/255.255.255.247').inspect
  #     #=> "#<IPv4: 192.168.1.1/255.255.255.247(!)>"
  #   IPAddress.parse('192.168.1.1/255.255.255.0').inspect
  #     #=> "#<IPv4: 192.168.1.1/255.255.255.0(24)>"
  def inspect
    "#<IPv4: #{to_s}/#{string_for_octets @mask_octets}(#{cidr? ? prefix_length: '!'})>"
  end
  
  def host?
    @mask_octets == FULL_MASK
  end
  
  def network?
    @octets == network_octets
  end

  def limited_broadcast?
    @octets == FULL_MASK
  end
  
  def directed_broadcast?
    @octets == directed_broadcast_octets
  end

  def broadcast?
    limited_broadcast? || directed_broadcast?
  end

  # @return [Version4]
  def network
    self.class.new network_octets, @mask_octets
  end

  # @return [Version4]
  def directed_broadcast
    self.class.new directed_broadcast_octets, @mask_octets
  end

  alias_method :broadcast, :directed_broadcast
  alias_method :last, :directed_broadcast
  
  def unicast?
    host? || (! (broadcast? || multicast?))
  end
  
  def multicast?
    _bits.take(4) == [1, 1, 1, 0]
  end

  # true if mask is /0 ~ /32
  def cidr?
    PREFIXIES.include? @mask_octets
  end
  
  # It is able to deal with "classfull"
  def classible?
    %w[a b c d e].any?{|s|__send__ :"class_#{s}?"}
  end

  # RFC791
  def class_a?
    (_bits.take(1) == [0]) && (prefix_lengh == 8)
  end
  
  # RFC791
  def class_b?
    (_bits.take(2) == [1, 0]) && (prefix_lengh == 16)
  end
  
  # RFC791
  def class_c?
    (_bits.take(3) == [1, 1, 0]) && (prefix_lengh == 24)
  end
  
  # RFC3171
  def class_d?
    new([224, 0, 0, 0], PREFIXIES[4]).cover? self
  end
  
  # RFC1112
  def class_e?
    new([240, 0, 0, 0], PREFIXIES[4]).cover? self
  end
  
  def cover?(other)
    family?(other) && 
      (network_octets..directed_broadcast_octets).cover?(other.octets)
  end

  alias_method :include?, :cover?
  alias_method :===, :cover?

  def family?(other)
    other.respond_to?(:ipv4address?) && other.ipv4address?
  end

  def ipv4address?
    true
  end

  def ipv6address?
    false
  end

  def segment?(other)
    family?(other) && <commit_msg>Be strict to check objects kind on #family?<commit_after># coding: us-ascii

module Net; module IPAddress; class Version4

  # @return [String]
  def to_s
    string_for_octets @octets
  end

  # @return [String]
  # @example
  #   IPAddress.parse('192.168.1.1/255.255.255.247').inspect
  #     #=> "#<IPv4: 192.168.1.1/255.255.255.247(!)>"
  #   IPAddress.parse('192.168.1.1/255.255.255.0').inspect
  #     #=> "#<IPv4: 192.168.1.1/255.255.255.0(24)>"
  def inspect
    "#<IPv4: #{to_s}/#{string_for_octets @mask_octets}(#{cidr? ? prefix_length: '!'})>"
  end
  
  def host?
    @mask_octets == FULL_MASK
  end
  
  def network?
    @octets == network_octets
  end

  def limited_broadcast?
    @octets == FULL_MASK
  end
  
  def directed_broadcast?
    @octets == directed_broadcast_octets
  end

  def broadcast?
    limited_broadcast? || directed_broadcast?
  end

  # @return [Version4]
  def network
    self.class.new network_octets, @mask_octets
  end

  # @return [Version4]
  def directed_broadcast
    self.class.new directed_broadcast_octets, @mask_octets
  end

  alias_method :broadcast, :directed_broadcast
  alias_method :last, :directed_broadcast
  
  def unicast?
    host? || (! (broadcast? || multicast?))
  end
  
  def multicast?
    _bits.take(4) == [1, 1, 1, 0]
  end

  # true if mask is /0 ~ /32
  def cidr?
    PREFIXIES.include? @mask_octets
  end
  
  # It is able to deal with "classfull"
  def classible?
    %w[a b c d e].any?{|s|__send__ :"class_#{s}?"}
  end

  # RFC791
  def class_a?
    (_bits.take(1) == [0]) && (prefix_lengh == 8)
  end
  
  # RFC791
  def class_b?
    (_bits.take(2) == [1, 0]) && (prefix_lengh == 16)
  end
  
  # RFC791
  def class_c?
    (_bits.take(3) == [1, 1, 0]) && (prefix_lengh == 24)
  end
  
  # RFC3171
  def class_d?
    new([224, 0, 0, 0], PREFIXIES[4]).cover? self
  end
  
  # RFC1112
  def class_e?
    new([240, 0, 0, 0], PREFIXIES[4]).cover? self
  end
  
  def cover?(other)
    family?(other) && 
      (network_octets..directed_broadcast_octets).cover?(other.octets)
  end

  alias_method :include?, :cover?
  alias_method :===, :cover?

  def family?(other)
    other.kind_of?(::Net::IPAddress) && other.ipv4address?
  end

  def ipv4address?
    true
  end

  def ipv6address?
    false
  end

  def segment?(other)
    family?(other) && 
{'fraction_non_alphanumeric': 0.14837310195227765, 'fraction_numerical': 0.06095444685466377, 'mean_word_length': 2.9545454545454546, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 16, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644635', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1873, 'n_words': 393}