Sha256: d1cd8542391aa55752d4336043c1a01bb8b76c44fea935fa61fe97e84db58b3b

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'ore/versions/exceptions/invalid_version'

require 'rubygems'

module Ore
  module Versions
    #
    # Represents a standard three-number version.
    #
    # @see http://semver.org/
    #
    class Version < Gem::Version

      # Major version number
      attr_reader :major

      # Minor version number
      attr_reader :minor

      # Patch version number
      attr_reader :patch

      # The build string
      attr_reader :build

      #
      # Creates a new version.
      #
      # @param [Integer, nil] major
      #   The major version number.
      #
      # @param [Integer, nil] minor
      #   The minor version number.
      #
      # @param [Integer, nil] patch
      #   The patch version number.
      #
      # @param [Integer, nil] build (nil)
      #   The build version number.
      #
      def initialize(major,minor,patch,build=nil)
        @major = (major || 0)
        @minor = (minor || 0)
        @patch = (patch || 0)
        @build = build

        numbers = [@major,@minor,@patch]
        numbers << @build if  @build

        super(numbers.join('.'))
      end

      #
      # Parses a version string.
      #
      # @param [String] string
      #   The version string.
      #
      # @return [Version]
      #   The parsed version.
      #
      def self.parse(string)
        major, minor, patch, build = string.split('.',4)

        return self.new(
          (major || 0).to_i,
          (minor || 0).to_i,
          (patch || 0).to_i,
          build
        )
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ore-core-0.1.5 lib/ore/versions/version.rb