lib/eff/package/semantic_version.rb in eff-0.0.1 vs lib/eff/package/semantic_version.rb in eff-0.0.2

- old
+ new

@@ -1,10 +1,13 @@ module Eff class Package class SemanticVersion - PARTS = %i(major minor patch release identity) + include Comparable + BASE_PARTS = %i(major minor patch) + PARTS = BASE_PARTS + %i(release identity) + PARTS.each do |part| attr_accessor part end def initialize(version_string) @@ -14,9 +17,18 @@ def to_h Hash[ PARTS.map { |part| [part, send(part)] } ] + end + + def <=>(other) + result = 0 + BASE_PARTS.each do |part| + result = self.public_send(part).to_i <=> other.public_send(part).to_i + break unless result == 0 + end + result end private def parse! remaining, @identity = @version_string.split("+")