Sha256: 906f302ba818d6dcc06afebbe6c2453ca7cdb6bec1d0d4c3564cd39336f934f1

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

module Eff
  class Package
    class SemanticVersion
      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)
        @version_string = version_string
        parse!
      end

      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("+")
        remaining, @release    = remaining.split("-")
        @major, @minor, @patch = remaining.split(".")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eff-0.0.2 lib/eff/package/semantic_version.rb