deb_version-1.0.3/0000755000004100000410000000000015055121672014046 5ustar www-datawww-datadeb_version-1.0.3/bin/0000755000004100000410000000000015055121671014615 5ustar www-datawww-datadeb_version-1.0.3/bin/setup0000755000004100000410000000020315055121671015676 0ustar www-datawww-data#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here deb_version-1.0.3/bin/console0000755000004100000410000000043515055121671016207 0ustar www-datawww-data#!/usr/bin/env ruby # frozen_string_literal: true require "bundler/setup" require "deb_version" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. require "irb" IRB.start(__FILE__) deb_version-1.0.3/lib/0000755000004100000410000000000015055121671014613 5ustar www-datawww-datadeb_version-1.0.3/lib/deb_version.rb0000644000004100000410000000140415055121671017436 0ustar www-datawww-data# frozen_string_literal: true require_relative "deb_version/version" require_relative "deb_version/compare" # Constants for the DebVersion class class DebVersion class Error < StandardError; end # String of ASCII characters which are considered punctuation characters in the C locale: # Except for ~ # Already sorted PUNCTUATION = "!\"\#$%&'()*+,-./:;<=>?@[]^_`{|}".chars DIGITS = ("0".."9").to_a # Sorted list of characters used by Debian Version sort. # see https://www.debian.org/doc/debian-policy/ch-controlfields.html#version SORT_LIST = ["~", ""] + ("A".."Z").to_a + ("a".."z").to_a + PUNCTUATION mapping = {} SORT_LIST.each_with_index do |char, index| mapping[char] = index end # Set it to a constant ORDER_MAPPING = mapping end deb_version-1.0.3/lib/deb_version/0000755000004100000410000000000015055121671017112 5ustar www-datawww-datadeb_version-1.0.3/lib/deb_version/compare.rb0000644000004100000410000000562515055121671021075 0ustar www-datawww-data# frozen_string_literal: true # Debian Version comparison class # This is based on the Python deb-pkg-tools implementation # https://github.com/xolox/python-deb-pkg-tools class DebVersion attr_reader :epoch, :upstream_version, :debian_revision include Comparable def initialize(version) @version = version @epoch = 0 @debian_revision = "" if @version.include? ":" @epoch, @version = @version.split(":") @epoch = @epoch.to_i end if @version.include? "-" @upstream_version, _, @debian_revision = @version.rpartition("-") else @upstream_version = @version end end # Convert to an array of [epoch, upstream_version, debian_revision] # Helpful for printing and debugging def to_a [@epoch, @upstream_version, @debian_revision] end def to_s result = "" result << "#{@epoch}:" if @epoch != 0 result << @upstream_version result << "-#{@debian_revision}" unless @debian_revision.empty? result end # Internal method to get the largest digit prefix def get_digit_prefix(characters) value = 0 value = (value * 10) + characters.shift.to_i while characters && DebVersion::DIGITS.include?(characters[0]) value end # Internal method to get the largest non-digit prefix def get_non_digit_prefix(characters) prefix = [] prefix << characters.shift while characters.size.positive? && !DebVersion::DIGITS.include?(characters[0]) prefix end # Compare strings as per https://www.debian.org/doc/debian-policy/ch-controlfields.html#version # Section 5.6.12 # This is used to compare upstream_version as well as debian_revision # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize def compare_strings(version1, version2) v1 = version1.chars v2 = version2.chars while !v1.empty? || !v2.empty? p1 = get_non_digit_prefix(v1) p2 = get_non_digit_prefix(v2) if p1 != p2 loop do c1 = p1.shift c2 = p2.shift break if c1.nil? && c2.nil? o1 = DebVersion::ORDER_MAPPING.fetch(c1 || "") o2 = DebVersion::ORDER_MAPPING.fetch(c2 || "") if o1 < o2 return -1 elsif o1 > o2 return 1 end end end d1 = get_digit_prefix(v1) d2 = get_digit_prefix(v2) if d1 < d2 return -1 elsif d1 > d2 return 1 end end 0 end # rubocop:enable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize # Compare two versions # using all 3 parts def <=>(other) return epoch <=> other.epoch if epoch != other.epoch result = compare_strings(upstream_version, other.upstream_version) return result if result != 0 return compare_strings(debian_revision, other.debian_revision) if debian_revision || other.debian_revision 0 end end deb_version-1.0.3/lib/deb_version/version.rb0000644000004100000410000000011015055121671021114 0ustar www-datawww-data# frozen_string_literal: true class DebVersion VERSION = "1.0.3" end deb_version-1.0.3/LICENSE.txt0000644000004100000410000000205715055121671015674 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2023 Nemo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. deb_version-1.0.3/README.md0000644000004100000410000000527715055121671015337 0ustar www-datawww-data# Debian Version (Ruby) [![License MIT](https://img.shields.io/badge/license-MIT-blue)](https://github.com/captn3m0/ruby-deb-version/blob/main/LICENSE.txt) [![Rubygems version](https://badgen.net/rubygems/v/deb_version)](https://rubygems.org/gems/deb_version) [![CI Status](https://badgen.net/github/checks/captn3m0/ruby-deb-version)](https://github.com/captn3m0/ruby-deb-version/actions/workflows/main.yml?query=branch%3Amain) ![Latest Tag](https://badgen.net/github/tag/captn3m0/ruby-deb-version) [![GitHub issues](https://img.shields.io/github/issues-raw/captn3m0/ruby-deb-version?color=orange&logo=github&logoColor=white)](https://github.com/captn3m0/ruby-deb-version/issues?q=is%3Aissue+is%3Aopen) A port of "Debian Version" comparison function to Ruby. This is based on [Debian Policy Manual v4.6.20, Section 5.6.12](https://www.debian.org/doc/debian-policy/ch-controlfields.html#version). It adapts some of the code and tests from https://github.com/FauxFaux/deb-version and https://github.com/xolox/python-deb-pkg-tools ## Installation Install the gem and add to the application's Gemfile by executing: $ bundle add deb_version If bundler is not being used to manage dependencies, install the gem by executing: $ gem install deb_version ## Usage ```ruby require 'deb_version' v1 = DebVersion.new("1.3~rc2") v2 = DebVersion.new("1.3") v1 < v2 # true ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). Run `bundle exec rake rubocop` to check for style violations. Run `bundle exec rake test` to run tests. See [HACKING.md](HACKING.md) for further details. ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/captn3m0/ruby-deb-version. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/captn3m0/ruby-deb-version/blob/main/CODE_OF_CONDUCT.md). ## License The gem is available as open source under the terms of the [MIT License](https://nemo.mit-license.org/). ## Code of Conduct Everyone interacting in the DebVersion project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/captn3m0/ruby-deb-version/blob/main/CODE_OF_CONDUCT.md). deb_version-1.0.3/CHANGELOG.md0000644000004100000410000000037715055121671015665 0ustar www-datawww-data## [Unreleased] ## [1.0.3] - 2025-08-25 - Drops Ruby 3.0 - Adds Ruby 3.3, 3.4 ## [1.0.2] - 2023-05-30 - Dependency cleanup ## [1.0.1] - 2023-05-30 - Bug fix for versions using `z` - Adds a new `to_s` method. ## [0.1.0] - 2023-05-07 - Initial release deb_version-1.0.3/deb_version.gemspec0000644000004100000410000000254315055121672017716 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: deb_version 1.0.3 ruby lib Gem::Specification.new do |s| s.name = "deb_version".freeze s.version = "1.0.3".freeze s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.metadata = { "changelog_uri" => "https://github.com/captn3m0/ruby-deb-version/blob/main/CHANGELOG.md", "homepage_uri" => "https://github.com/captn3m0/ruby-deb-version", "rubygems_mfa_required" => "true", "source_code_uri" => "https://github.com/captn3m0/ruby-deb-version" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Nemo".freeze] s.date = "1980-01-02" s.email = ["rubygem@captnemo.in".freeze] s.files = ["CHANGELOG.md".freeze, "LICENSE.txt".freeze, "README.md".freeze, "bin/console".freeze, "bin/setup".freeze, "lib/deb_version.rb".freeze, "lib/deb_version/compare.rb".freeze, "lib/deb_version/version.rb".freeze] s.homepage = "https://github.com/captn3m0/ruby-deb-version".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 3.1.0".freeze) s.rubygems_version = "3.6.9".freeze s.summary = "A port of Debian Version comparison to Ruby.".freeze end