Sha256: 52459e4594223cdcd637b80a4ee03ae9d8b51a4d65dc6d50871ee6c8a9fac3f9
Contents?: true
Size: 1.29 KB
Versions: 12
Compression:
Stored size: 1.29 KB
Contents
module Serializable class Version def initialize(version_string) version_string = version_string.gsub('_','.') @levels = version_string.split('.') @levels.each_with_index do |number, index| @levels[index] = number.to_i end end def major get_level(0) end def minor get_level(1) end def build get_level(2) end def revision get_level(3) end def <(rhs) (self <=> rhs) < 0 end def >(rhs) (self <=> rhs) > 0 end def ==(rhs) (self <=> rhs) == 0 end def <=>(rhs) max_levels = @levels.size - 1 max_levels = rhs.levels.size - 1 if rhs.levels.size > max_levels (0..max_levels).each do |level| lhs_level = @levels[level] || 0 rhs_level = rhs.levels[level] || 0 if lhs_level == rhs_level next else return lhs_level <=> rhs_level end end 0 # Ended on an equality end def to_s(seperator = '.') @levels.join(seperator) end def to_s_underscored to_s('_') end protected def levels @levels end private def get_level(level) if @levels.size > level @levels[level] else 0 end end end end
Version data entries
12 entries across 12 versions & 2 rubygems