<commit_before># coding: us-ascii
# Copyright (c) 2012 <NAME>

module Net; module IPAddress

  # Called "octets" is expected a FixedArray the 4 length,
  # that's members 0~255 Fixnum.
  # And the "mask_octets" is same format with the octets.
  # @see #octets, #mask_octets
  def initialize(octets, mask_octets=self.class::FULL_MASK)
    raise InvalidAddress unless valid_octets? octets
    raise TypeError unless valid_octets? mask_octets

    @octets, @mask_octets = octets.dup.freeze, mask_octets.dup.freeze
  end

  # @return [Array<Fixnum>]
  # @example 
  #   IPAddress('192.168.1.1/24').octets #=> [192, 168, 1 ,1]
  def octets
    @octets.dup
  end

  alias_method :bytes, :octets

  # @return [Array<Fixnum>]
  # @example 
  #   IPAddress('192.168.1.1/24').mask_octets #=> [255, 255, 255, 0]
  def mask_octets
    @mask_octets.dup
  end

  alias_method :netmask, :mask_octets
  
  # @return [Array<Fixnum>]
  # @example 
  #   IPAddress('192.168.1.1/24').bits
  #    #=> [1, 1, 0, 0, 0, 0, 0, 0,
  #         1, 0, 1, 0, 1, 0, 0, 0,
  #         0, 0, 0, 0, 0, 0, 0, 1,
  #         0, 0, 0, 0, 0, 0, 0, 1]
  def bits
    _bits.dup
  end

  alias_method :netmask, :mask_octets

  def ipaddress?
    true
  end

  # @return [self]
  def to_ipaddress
    self
  end

  # @return [0, 1, nil]
  def <=>(other)
    family?(other) ? (@octets <=> other.octets) : nil
  end

  def eql?(other)
    family?(other) && (values == other.values)
  end

  alias_method :==, :eql?

  # @return [Number]
  def hash
    values.hash
  end

  # @return [self]
  def freeze
    memorize
    super
  end
  
  # @return [Boolean]
  def ===(other)
    cover? other
  end

  # @return [String]
  # @example
  #   IPAddress('192.168.1.1').big_endian #=> "\xC0\xA8\x01\x01"
  def big_endian
    @octets.pack 'C4'
  end

  alias_method :byte_order, :big_endian

  # @return [Range]
  def to_range
    network..last
  end

  # @todo
  # @return [Integer]
  def space
    hosts(true).to_a.size
  end

  # @todo
  # @return [Integer]
  def host_counts
    hosts.to_a.size
  end
  
  # @return [self]
  def each_host(contain_network=false, &block)
    return to_enum(__callee__, contain_network) unless block_given?

    range = (contain_network ? network : network.next)...last
    range.__send__ :each, &block
  end

  alias_method :hosts, :each_host

  # @return [self]
  def each_address(&block)
    return to_enum(__callee__) unless block_given?

    to_range.__send__ :each, &block
  end
<commit_msg>Add YARD<commit_after># coding: us-ascii
# Copyright (c) 2012 <NAME>

module Net; module IPAddress

  # Called "octets" is expected a FixedArray the 4 length,
  # that's members 0~255 Fixnum.
  # And the "mask_octets" is same format with the octets.
  # @see #octets, #mask_octets
  def initialize(octets, mask_octets=self.class::FULL_MASK)
    raise InvalidAddress unless valid_octets? octets
    raise TypeError unless valid_octets? mask_octets

    @octets, @mask_octets = octets.dup.freeze, mask_octets.dup.freeze
  end

  # @return [Array<Fixnum>]
  # @example 
  #   IPAddress('192.168.1.1/24').octets #=> [192, 168, 1 ,1]
  def octets
    @octets.dup
  end

  alias_method :bytes, :octets

  # @return [Array<Fixnum>]
  # @example 
  #   IPAddress('192.168.1.1/24').mask_octets #=> [255, 255, 255, 0]
  def mask_octets
    @mask_octets.dup
  end

  alias_method :netmask, :mask_octets
  
  # @return [Array<Fixnum>]
  # @example 
  #   IPAddress('192.168.1.1/24').bits
  #    #=> [1, 1, 0, 0, 0, 0, 0, 0,
  #         1, 0, 1, 0, 1, 0, 0, 0,
  #         0, 0, 0, 0, 0, 0, 0, 1,
  #         0, 0, 0, 0, 0, 0, 0, 1]
  def bits
    _bits.dup
  end

  alias_method :netmask, :mask_octets

  def ipaddress?
    true
  end

  # @return [self]
  def to_ipaddress
    self
  end

  # @return [0, 1, nil]
  def <=>(other)
    family?(other) ? (@octets <=> other.octets) : nil
  end

  def eql?(other)
    family?(other) && (values == other.values)
  end

  alias_method :==, :eql?

  # @return [Number]
  def hash
    values.hash
  end

  # @return [self]
  def freeze
    memorize
    super
  end
  
  # @return [Boolean]
  def ===(other)
    cover? other
  end

  # @return [String]
  # @example
  #   IPAddress('192.168.1.1').big_endian #=> "\xC0\xA8\x01\x01"
  def big_endian
    @octets.pack 'C4'
  end

  alias_method :byte_order, :big_endian

  # @return [Range]
  def to_range
    network..last
  end

  # @todo
  # @return [Integer]
  def space
    hosts(true).to_a.size
  end

  # @todo
  # @return [Integer]
  def host_counts
    hosts.to_a.size
  end
  
  # @param contain_network [Boolean]
  # @return [self]
  def each_host(contain_network=false, &block)
    return to_enum(__callee__, contain_network) unless block_given?

    range = (contain_network ? network : network.next)...last
    range.__send__ :each, &block
  end

  alias_method :hosts, :each_host

  # @return [self]
  def each_address(&block)
    return to_enum(__callee__) unless block_given?

    to_range.__send__ :each, &block
  end

{'fraction_non_alphanumeric': 0.13501602564102563, 'fraction_numerical': 0.04246794871794872, 'mean_word_length': 2.8407692307692307, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '5423387', 'n_tokens_mistral': 2154, 'n_tokens_neox': 1941, 'n_words': 488}