Sha256: 90481a3e657b5a52f43e56a532b51b8b280532ab53b413c8183493a8c9e60186

Contents?: true

Size: 731 Bytes

Versions: 3

Compression:

Stored size: 731 Bytes

Contents

# frozen_string_literal: true

require 'rubygems'

module Xezat
  class Cygversion
    attr_reader :version

    def initialize(str)
      matched = str.match(/(.+)-(.+)/)
      version = matched[1]
      @release = matched[2]
      split = version.split('+')
      @version = split[0].tr('_', '.')
      @revision = split.length >= 2 ? split[1].match(/(\d+)/)[0].to_i : Time.at(0).strftime('%Y%m%d').to_i
    end

    def to_v
      [Gem::Version.new(@version), @revision, @release]
    rescue ArgumentError
      to_a
    end

    def to_a
      [@version, @revision, @release]
    end

    def <=>(other)
      result = (to_v <=> other.to_v)
      return result unless result.nil?

      (to_a <=> other.to_a)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xezat-0.3.1 lib/xezat/cygversion.rb
xezat-0.3.0 lib/xezat/cygversion.rb
xezat-0.2.3 lib/xezat/cygversion.rb