<commit_before>module IpAsInt::Ip2int

  def ip2int(ip_string)
    ip2a(ip_string).pack('C*').unpack('N').first
    #ip_string.split('.').inject(0) { |total,value| (total << 8 ) + value.to_i }
  end

  def int2ip(ip_int)
    if ip_int
      [ip_int].pack('N').unpack('C*').join('.')
      #[24, 16, 8, 0].collect {|b| (address >> b) & 255}.join('.')IpAsInt::
    else
      ""
    end
  end

  def ip2a(ip_string)
    if ip_string.is_a(Integer)
      return ip_string
    end
    ip_a = ip_string.split('.')
    raise(ArgumentError, "Invalid IP: need 4 parts") unless ip_a.length == 4
    rexp = /^\d+$/
    raise(ArgumentError, "Invalid IP: illegal format") unless ip_a.all? { |x| rexp.match(x) }
    ip_a = ip_a.map(&:to_i)
    raise(ArgumentError, "Invalid IP: integer out of range") unless ip_a.all? { |x| (0..255).include? x
    ip_a
  end

end
<commit_msg>Update ip2int.rb<commit_after>module IpAsInt::Ip2int

  def ip2int(ip_string)
    ip2a(ip_string).pack('C*').unpack('N').first
    #ip_string.split('.').inject(0) { |total,value| (total << 8 ) + value.to_i }
  end

  def int2ip(ip_int)
    if ip_int
      [ip_int].pack('N').unpack('C*').join('.')
      #[24, 16, 8, 0].collect {|b| (address >> b) & 255}.join('.')IpAsInt::
    else
      ""
    end
  end

  def ip2a(ip_string)
    if ip_string.is_a(Integer)
      return int2ip(ip_string)
    end
    ip_a = ip_string.split('.')
    raise(ArgumentError, "Invalid IP: need 4 parts") unless ip_a.length == 4
    rexp = /^\d+$/
    raise(ArgumentError, "Invalid IP: illegal format") unless ip_a.all? { |x| rexp.match(x) }
    ip_a = ip_a.map(&:to_i)
    raise(ArgumentError, "Invalid IP: integer out of range") unless ip_a.all? { |x| (0..255).include? x
    ip_a
  end

end

{'fraction_non_alphanumeric': 0.18040345821325648, 'fraction_numerical': 0.026512968299711816, 'mean_word_length': 3.0655737704918034, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '886002', 'n_tokens_mistral': 727, 'n_tokens_neox': 700, 'n_words': 147}