deb-version-1.0.2/0000755000175000017500000000000014542277607015043 5ustar thegodtunethegodtunedeb-version-1.0.2/lib/0000755000175000017500000000000014542277607015611 5ustar thegodtunethegodtunedeb-version-1.0.2/lib/deb_version/0000755000175000017500000000000014542277607020110 5ustar thegodtunethegodtunedeb-version-1.0.2/lib/deb_version/version.rb0000644000175000017500000000011014542277607022112 0ustar thegodtunethegodtune# frozen_string_literal: true class DebVersion VERSION = "1.0.2" end deb-version-1.0.2/lib/deb_version/compare.rb0000644000175000017500000000562514542277607022073 0ustar thegodtunethegodtune# 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.2/lib/deb_version.rb0000644000175000017500000000140414542277607020434 0ustar thegodtunethegodtune# 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.2/LICENSE.txt0000644000175000017500000000205714542277607016672 0ustar thegodtunethegodtuneThe 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.2/README.md0000644000175000017500000000402314542277607016321 0ustar thegodtunethegodtune# Debian Version (Ruby) 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 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://opensource.org/licenses/MIT). ## 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.2/deb_version.gemspec0000644000175000017500000000253214542277607020711 0ustar thegodtunethegodtune######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: deb_version 1.0.2 ruby lib Gem::Specification.new do |s| s.name = "deb_version".freeze s.version = "1.0.2" 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/README.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 = "2023-05-30" 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.0.0".freeze) s.rubygems_version = "3.4.20".freeze s.summary = "A port of Debian Version comparison to Ruby.".freeze end deb-version-1.0.2/CHANGELOG.md0000644000175000017500000000022214542277607016650 0ustar thegodtunethegodtune## [Unreleased] ## [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.2/bin/0000755000175000017500000000000014542277607015613 5ustar thegodtunethegodtunedeb-version-1.0.2/bin/setup0000755000175000017500000000020314542277607016674 0ustar thegodtunethegodtune#!/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.2/bin/console0000755000175000017500000000043514542277607017205 0ustar thegodtunethegodtune#!/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__)