class Version

Constants

InvalidRequire
InvalidVersion
MSGS
REQUIRE
VERSION

Attributes

nums[R]

Public Class Methods

new(str) click to toggle source
# File lib/dpl/support/version.rb, line 17
def initialize(str)
  @nums = split(str) || raise(InvalidVersion, MSGS[:version] % str)
end

Public Instance Methods

!=(other) click to toggle source
# File lib/dpl/support/version.rb, line 41
def !=(other)
  trunc(other.size).to_a != other.to_a
end
<=>(other) click to toggle source
# File lib/dpl/support/version.rb, line 45
def <=>(other)
  to_a <=> other.to_a
end
==(other) click to toggle source
# File lib/dpl/support/version.rb, line 37
def ==(other)
  trunc(other.size).to_a == other.to_a
end
bump() click to toggle source
# File lib/dpl/support/version.rb, line 55
def bump
  ix = nums[1] ? -2 : -1
  nums[ix] = nums[ix] + 1
  nums[-1] = nums[-1] = 0 if nums[1]
  self
end
clone() click to toggle source
# File lib/dpl/support/version.rb, line 67
def clone
  Version.new(to_s)
end
satisfies?(str) click to toggle source
# File lib/dpl/support/version.rb, line 21
def satisfies?(str)
  send(*parse(str) || raise(InvalidRequire, MSGS[:require] % str))
end
size() click to toggle source
# File lib/dpl/support/version.rb, line 25
def size
  nums.size
end
to_a() click to toggle source
# File lib/dpl/support/version.rb, line 29
def to_a
  nums
end
to_s() click to toggle source
# File lib/dpl/support/version.rb, line 33
def to_s
  nums.join('.')
end
trunc(size) click to toggle source
# File lib/dpl/support/version.rb, line 62
def trunc(size)
  @nums = nums[0..size - 1]
  self
end

Private Instance Methods

parse(str) click to toggle source
# File lib/dpl/support/version.rb, line 79
def parse(str)
  op, version = str =~ REQUIRE && [::Regexp.last_match(1), ::Regexp.last_match(2)]
  op = '==' if op == '='
  [op, Version.new(version)] if op
end
split(str) click to toggle source
# File lib/dpl/support/version.rb, line 75
def split(str)
  str =~ VERSION && [::Regexp.last_match(1), ::Regexp.last_match(2), ::Regexp.last_match(3)].compact.map(&:to_i)
end