<commit_before>#
# Encodes version-numbering logic into a convenient class.
#
class Version
  include Comparable
  
  #
  # Creates a new Version number, with a +major+ version number, +minor+
  # revision number, +revision+ number, and optionally more (unnamed)
  # version components.
  #
  def initialize(major, minor = 0, revision = nil, *rest)
    self.components = [ major, minor, revision, *rest ].compact
  end
  
  [ :major, :minor, :revision ].each.with_index do |component, index|
    define_method(:"#{component}")  {    self[index]          }
    define_method(:"#{component}=") {|v| self[index] = v.to_s }
  end
  
  def [](index)
    self.components[index]
  end
  
  def []=(index, value)
    if index < self.length
      length = self.length - index
      zeroes = Array.new(length - 1, 0)
      
      self.components[index, length] = [ value, *zeroes ]
    else
      length = (self.length - index).abs
      zeroes = Array.new(length, 0)
      
      self.components[index - length, length] = (zeroes << value)
    end
  end
  
  def bump(part = self.length)
    self.dup.bump!(part)
  end
  
  def bump!(part = self.length)
    before = self.to_a.take(part + 1)
    after  = self.to_a.drop(part + 1)
    
    before[-1] = before[-1].succ
    after      = Array.new(after.length, 0)
    
    from_a(before + after)
  def resize!(length)
    self.components = self.components[0, length]
    self
  end
  
    self
  end
  
  def length
    self.components.length
  end
  
  #
  # Compares a Version against any +other+ object that responds to
  # +to_version+.
  #
  def <=>(other)
    self.to_a <=> other.to_version.to_a
  end<commit_msg>Improved bump algorithm<commit_after>#
# Encodes version-numbering logic into a convenient class.
#
class Version
  include Comparable
  
  #
  # Creates a new Version number, with a +major+ version number, +minor+
  # revision number, +revision+ number, and optionally more (unnamed)
  # version components.
  #
  def initialize(major, minor = 0, revision = nil, *rest)
    self.components = [ major, minor, revision, *rest ].compact
  end
  
  [ :major, :minor, :revision ].each.with_index do |component, index|
    define_method(:"#{component}")  {    self[index]          }
    define_method(:"#{component}=") {|v| self[index] = v.to_s }
  end
  
  def [](index)
    self.components[index]
  end
  
  def []=(index, value)
    if index < self.length
      length = self.length - index
      zeroes = Array.new(length - 1, 0)
      
      self.components[index, length] = [ value, *zeroes ]
    else
      length = (self.length - index).abs
      zeroes = Array.new(length, 0)
      
      self.components[index - length, length] = (zeroes << value)
    end
  end
  
  def resize!(length)
    self.components = self.components[0, length]
    self
  end
  
  def bump!(part = self.length - 1, trim = false)
    self.resize!(part + 1) if trim
    self[part] = (self[part] || -1).succ
    self
  end
  
  def length
    self.components.length
  end
  
  #
  # Compares a Version against any +other+ object that responds to
  # +to_version+.
  #
  def <=>(other)
    self.to_a <=> other.to_version.to_a
  end
{'fraction_non_alphanumeric': 0.12796208530805686, 'fraction_numerical': 0.005687203791469194, 'mean_word_length': 2.6100342075256555, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3985097', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1071, 'n_words': 285}