class MrBump::Version

This class enables comparison and bumping of sementic versions and conversion to and from strings

Attributes

major[R]
minor[R]
patch[R]

Public Class Methods

new(version_str) click to toggle source
# File lib/mr_bump/version.rb, line 11
def initialize(version_str)
  regex = Regexp.new('^([0-9]+)(\.([0-9]+)(\.([0-9]*))?)?')
  numbers = version_str.match(regex).captures
  @major = numbers[0].to_i
  @minor = numbers.size > 2 ? numbers[2].to_i : 0
  @patch = numbers.size > 4 ? numbers[4].to_i : 0
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/mr_bump/version.rb, line 19
def <=>(other)
  major_com = major <=> other.major
  minor_com = major_com.zero? ? minor <=> other.minor : major_com
  minor_com.zero? ? patch <=> other.patch : minor_com
end
bump_major() click to toggle source
# File lib/mr_bump/version.rb, line 29
def bump_major
  dup.bump_major!
end
bump_major!() click to toggle source
# File lib/mr_bump/version.rb, line 33
def bump_major!
  @major += 1
  @minor = 0
  @patch = 0
  self
end
bump_minor() click to toggle source
# File lib/mr_bump/version.rb, line 40
def bump_minor
  dup.bump_minor!
end
bump_minor!() click to toggle source
# File lib/mr_bump/version.rb, line 44
def bump_minor!
  @minor += 1
  @patch = 0
  self
end
bump_patch() click to toggle source
# File lib/mr_bump/version.rb, line 50
def bump_patch
  dup.bump_patch!
end
bump_patch!() click to toggle source
# File lib/mr_bump/version.rb, line 54
def bump_patch!
  @patch += 1
  self
end
to_s() click to toggle source
# File lib/mr_bump/version.rb, line 25
def to_s
  "#{major}.#{minor}.#{patch}"
end