Sha256: b919079b3a969473a7926857dc0e733ef892726b34b9cdb595cb0d55dbb2ea0c
Contents?: true
Size: 1.15 KB
Versions: 5
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true module Releasetool class Version attr_reader :ident def initialize(ident) raise "Not a valid version identifier: #{ident.inspect}" unless ident.is_a?(String) @ident = ident end def next_patch self.class.normalized(segments[0], segments[1], incremented(segments[2])) end def next_minor self.class.normalized(segments[0], incremented(segments[1]), 0) end def next_major self.class.normalized(incremented(segments[0]), 0, 0) end def to_s if @ident[0] == "v" @ident else "v#{@ident}" end end def to_s_without_v if @ident[0] == "v" @ident[1..-1] else @ident end end def ==(other) other.is_a?(Releasetool::Version) && ident == other.ident end def self.normalized(major, minor, patch) new("v#{major}.#{minor}.#{patch}") end private def incremented(number) raise "Can't work out next version from #{self}" unless number.to_i.to_s == number number.to_i + 1 end def segments @segments ||= to_s_without_v.split(".") end end end
Version data entries
5 entries across 5 versions & 1 rubygems