Sha256: ef8720ae0c16bf94103afc36eef91f02019a193d2f84623bc5f0a4c70866fc71

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module VersionGem
  module Api
    # The version number as a string
    #
    # @return [String]
    def to_s
      self::VERSION
    end

    # The major version
    #
    # @return [Integer]
    def major
      @major ||= _to_a[0].to_i
    end

    # The minor version
    #
    # @return [Integer]
    def minor
      @minor ||= _to_a[1].to_i
    end

    # The patch version
    #
    # @return [Integer]
    def patch
      @patch ||= _to_a[2].to_i
    end

    # The pre-release version, if any
    #
    # @return [String, NilClass]
    def pre
      @pre ||= _to_a[3]
    end

    # The version number as a hash
    #
    # @return [Hash]
    def to_h
      @to_h ||= {
        major: major,
        minor: minor,
        patch: patch,
        pre: pre
      }
    end

    # The version number as an array of cast values
    #
    # @return [Array<[Integer, String, NilClass]>]
    def to_a
      @to_a ||= [major, minor, patch, pre]
    end

    private

    # The version number as an array of strings
    #
    # @return [Array<String>]
    def _to_a
      @_to_a = self::VERSION.split('.')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
version_gem-1.1.2 lib/version_gem/api.rb
version_gem-1.1.1 lib/version_gem/api.rb