Module: Semmy::VersionString

Extended by:
VersionString
Included in:
VersionString
Defined in:
lib/semmy/version_string.rb

Defined Under Namespace

Classes: NoPreviousMinor, SuffixNotFound, UnexpectedSuffix

Instance Method Summary collapse

Instance Method Details

#bump_minor(version, suffix) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/semmy/version_string.rb', line 21

def bump_minor(version, suffix)
  components = version.split('.')

  unless components.last =~ /^[0-9]+$/
    fail(UnexpectedSuffix, "Expected a version without suffix, found #{version}.")
  end

  components.map!(&:to_i)
  components[1] += 1
  components << suffix

  components.join('.')
end

#components(version) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/semmy/version_string.rb', line 50

def components(version)
  components = version.split('.')

  {
    major: components[0],
    minor: components[1],
    patch: components[2]
  }
end

#minor_only(version) ⇒ Object



46
47
48
# File 'lib/semmy/version_string.rb', line 46

def minor_only(version)
  version.split('.')[0..1].join('.')
end

#previous_minor(version) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/semmy/version_string.rb', line 35

def previous_minor(version)
  components = version.split('.').map(&:to_i)

  if components[1] == 0
    fail(NoPreviousMinor, "Cannot get previous minor of #{version}.")
  end

  components[1] -= 1
  components.join('.')
end

#remove_suffix(version, suffix) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/semmy/version_string.rb', line 11

def remove_suffix(version, suffix)
  new_version = version.dup

  unless new_version.gsub!(/.#{suffix}$/, '')
    fail(SuffixNotFound, "Suffix #{suffix} not found in #{version}")
  end

  new_version
end