Sha256: 718d4bcfb790be4e95c52b6a76eaa294ae40d5cb86181443e7448e3d855a2383

Contents?: true

Size: 1.52 KB

Versions: 12

Compression:

Stored size: 1.52 KB

Contents

require 'ore/versions/exceptions/invalid_version'

require 'rubygems/version'

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

12 entries across 12 versions & 2 rubygems

Version Path
ore-core-0.1.4 lib/ore/versions/version.rb
ore-core-0.1.3 lib/ore/versions/version.rb
ore-core-0.1.2 lib/ore/versions/version.rb
ore-core-0.1.1 lib/ore/versions/version.rb
ore-core-0.1.0 lib/ore/versions/version.rb
ore-0.2.3 lib/ore/versions/version.rb
ore-0.2.2 lib/ore/versions/version.rb
ore-0.2.1 lib/ore/versions/version.rb
ore-0.2.0 lib/ore/versions/version.rb
ore-0.1.4 lib/ore/versions/version.rb
ore-0.1.3 lib/ore/versions/version.rb
ore-0.1.2 lib/ore/versions/version.rb