Sha256: 44b5cd4df0d657de10ec91512c8e276c089746deec19d78b5a2148c2d2befb1f
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
module Semmy module VersionString extend self class SuffixNotFound < Error; end class UnexpectedSuffix < Error; end class NoPreviousMinor < Error; end 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 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 def minor_only(version) version.split('.')[0..1].join('.') end def components(version) components = version.split('.') { major: components[0], minor: components[1], patch: components[2] } end def previous_version(version) components = version.split('.').map(&:to_i) if components[2] > 0 components[2] -= 1 elsif components[1] > 0 components[1] -= 1 else fail(NoPreviousMinor, "Cannot get previous version of #{version}.") end components.join('.') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
semmy-0.3.0 | lib/semmy/version_string.rb |
semmy-0.2.1 | lib/semmy/version_string.rb |