<commit_before>require "naturally/version"

module Naturally
  
  # Perform a natural sort.
  #
  # @param [Array<String>] an_array the list of numbers to sort.
  # @return [Array<String>] the numbers sorted naturally.
  def self.sort(an_array)
    return an_array.sort_by { |x| normalize(x) }
  end  

  # Convert the given number into an object that can be sorted
  # naturally. This object is an array of {NumberElement} instances.
  #
  # @param [String] number the number in complex form such as 1.2a.3.
  # @return [Array<NumberElement>] an array of NumberElements which is
  #         able to be sorted naturally via a normal 'sort'.
  def self.normalize(number)
    number.to_s.scan(%r/[0-9a-zA-Z]+/o).map { |i| NumberElement.new(i) }
  end

  private

  # An entity which can be compared to other like elements for
  # sorting in an array. It's an object representing
  # a value which implements the {Comparable} interface.
  class NumberElement
    include Comparable
    attr_accessor :val

    def initialize(v)
      @val = v<commit_msg>style<commit_after>require 'naturally/version'

module Naturally
  # Perform a natural sort.
  #
  # @param [Array<String>] an_array the list of numbers to sort.
  # @return [Array<String>] the numbers sorted naturally.
  def self.sort(an_array)
    return an_array.sort_by { |x| normalize(x) }
  end  

  # Convert the given number into an object that can be sorted
  # naturally. This object is an array of {NumberElement} instances.
  #
  # @param [String] number the number in complex form such as 1.2a.3.
  # @return [Array<NumberElement>] an array of NumberElements which is
  #         able to be sorted naturally via a normal 'sort'.
  def self.normalize(number)
    number.to_s.scan(%r/[0-9a-zA-Z]+/o).map { |i| NumberElement.new(i) }
  end

  private

  # An entity which can be compared to other like elements for
  # sorting in an array. It's an object representing
  # a value which implements the {Comparable} interface.
  class NumberElement
    include Comparable
    attr_accessor :val

    def initialize(v)
      @val = v
{'fraction_non_alphanumeric': 0.0899091343854615, 'fraction_numerical': 0.004782400765184123, 'mean_word_length': 3.3045267489711936, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6491126', 'n_tokens_mistral': 663, 'n_tokens_neox': 632, 'n_words': 241}