Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#increment_semver(semver, increment_type = "patch") ⇒ Object

! /usr/bin/env ruby



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/increment_semver.rb', line 2

def increment_semver(semver, increment_type = "patch")
  if not (/\d+\.\d+\.\d+/).match(semver)
    raise "Your semantic version must match the format 'X.X.X'."
  end
  if not ["patch", "minor", "major"].include?(increment_type)
    raise "Only 'patch', 'minor', and 'major' are supported increment types."
  end

  major, minor, patch = semver.split(".")
  case increment_type
    when "patch"
      patch = patch.to_i + 1
    when "minor"
      minor = minor.to_i + 1
    when "major"
      major = major.to_i + 1
  end

  return "#{major}.#{minor}.#{patch}"
end