lib/semmy/version_string.rb in semmy-0.4.0 vs lib/semmy/version_string.rb in semmy-1.0.0

- old
+ new

@@ -16,22 +16,20 @@ end new_version end + def bump_major(version, suffix) + [bump(0, version), suffix].join('.') + end + def bump_minor(version, suffix) - components = version.split('.') + [bump(1, version), suffix].join('.') + end - 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('.') + def bump_patch_level(version) + bump(2, version) end def minor_only(version) version.split('.')[0..1].join('.') end @@ -68,19 +66,32 @@ stable_branch_name_pattern % previous_minor_version_components(version) end private + def bump(component_index, version) + components = version.split('.')[0..2].map!(&:to_i) + + [ + components[0...component_index], + components[component_index] + 1, + [0] * (2 - component_index) + ].flatten.join('.') + end + def previous_minor_version_components(version) components = version.split('.').map(&:to_i) if components[1].zero? - fail(NoPreviousMinor, "Cannot get previous minor version of #{version}.") + { + major: components[0] - 1, + minor: 'x' + } + else + { + major: components[0], + minor: components[1] - 1 + } end - - { - major: components[0], - minor: components[1] - 1 - } end end end