Sha256: 5f98219e501eb0574aac3623c5bf4bdfd8d81ac64d336772c37438caebd3a447

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Invoker
  class Version
    include Comparable
    attr_reader :major, :minor, :patch

    def initialize(number)
      t_major, t_minor, t_patch = number.split('.')
      @major = t_major.to_i
      @minor = t_minor.to_i
      @patch = t_patch.to_i
    end

    def to_a
      [major, minor, patch].compact
    end

    def <=>(version)
      (major.to_i <=> version.major.to_i).nonzero? ||
        (minor.to_i <=> version.minor.to_i).nonzero? ||
        patch.to_i <=> version.patch.to_i
    end

    def matches?(operator, number)
      version = Version.new(number)
      self == version

      return self == version if operator == '='
      return self > version  if operator == '>'
      return self < version  if operator == '<'
      return version <= self && version.next > self if operator  == '~>'
    end

    def next
      next_splits = to_a

      if next_splits.length == 1
        next_splits[0] += 1
      else
        next_splits[-2] += 1
        next_splits[-1] = 0
      end

      Version.new(next_splits.join('.'))
    end
  end
  VERSION = "1.5.1"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
invoker-1.5.1 lib/invoker/version.rb