class KXI::Application::Version

Represents a version of semantic versioning 2.0.0 (semver.org)

Public Class Methods

new(major, minor = 0, patch = 0, id = nil, meta = nil) click to toggle source

Instantiates the {KXI::Application::Version} class @param [integer] major Major number of version @param [integer] minor Minor number of version @param [integer] patch Patch number of version @param [string,nil] id Identifier of version @param [string,nil] meta Metadata of version

# File lib/kxi/application/version.rb, line 43
def initialize(major, minor = 0, patch = 0, id = nil, meta = nil)
        @major = major
        @minor = minor
        @patch = patch
        @id    = id
        @meta  = meta
end
parse(str) click to toggle source

Parses a version from its string representation @param [string] str String representation of the version @return [KXI::Application::Version] Version equivalent to given string

# File lib/kxi/application/version.rb, line 100
def self.parse(str)
        m = /^\s*(?'ma'\d+)\s*(\.\s*(?'mi'\d+))?\s*(\.\s*(?'pt'\d+))?\s*(-\s*(?'id'[0-9A-Z\-.]+))?\s*(\+\s*(?'mt'[0-9A-Z\-.]+))?\s*$/mi.match(str)
        raise(KXI::Exceptions::ParseException.new('version', str)) if m == nil
        return Version.new(m['ma'].to_i, m['mi'] != nil ? m['mi'].to_i : 0, m['pt'] != nil ? m['pt'].to_i : 0, m['id'], m['mt'])
end

Public Instance Methods

<(other) click to toggle source

Checks whether this version is lower than other version @return [bool] True when this version is lower than the other; false otherwise

# File lib/kxi/application/version.rb, line 66
def <(other)
        raise(KXI::Exceptions::InvalidTypeException.new(other.class, KXI::Application::Version)) unless other.is_a?(KXI::Application::Version)
        return true if @major < other.major or @minor < other.minor or @patch < other.patch
        return true if @id != nil and other.identifier == nil
        return true if @id != nil and other.identifier != nil and @id < other.identifier
        return false
end
<=(other) click to toggle source

Checks whether this version is lower than or equivalent to other version @return [bool] True when this version is lower than or equivalent to the other; false otherwise

# File lib/kxi/application/version.rb, line 76
def <=(other)
        raise(KXI::Exceptions::InvalidTypeException.new(other.class, KXI::Application::Version)) unless other.is_a?(KXI::Application::Version)
        return true if self == other
        return true if @major < other.major or @minor < other.minor or @patch < other.patch
        return true if @id != nil and other.identifier == nil
        return true if @id != nil and other.identifier != nil and @id < other.identifier
        return false
end
==(other) click to toggle source

Checks whether this version is equivalent to other version @return [bool] True when versions are equivalent; false otherwise

# File lib/kxi/application/version.rb, line 59
def ==(other)
        return false unless other.is_a?(KXI::Application::Version)
        return (@major == other.major and @minor == other.minor and @patch == other.patch and @id == other.identifier)
end
>(other) click to toggle source

Checks whether this version is grater than other version @return [bool] True when this version is grater than the other; false otherwise

# File lib/kxi/application/version.rb, line 87
def >(other)
        return (not self <= other)
end
>=(other) click to toggle source

Checks whether this version is grater than or equivalent to other version @return [bool] True when this version is grater than or equivalent to the other; false otherwise

# File lib/kxi/application/version.rb, line 93
def >=(other)
        return (not self < other)
end
identifier() click to toggle source

Gets the identifier of version @return [string] Identifier of version

# File lib/kxi/application/version.rb, line 27
def identifier
        @id
end
major() click to toggle source

Gets the major number of version @return [integer] Major number of version

# File lib/kxi/application/version.rb, line 9
def major
        @major
end
metadata() click to toggle source

Gets the metadata of version @return [string] Metadata of version

# File lib/kxi/application/version.rb, line 33
def metadata
        @meta
end
minor() click to toggle source

Gets the number minor of version @return [integer] Minor number of version

# File lib/kxi/application/version.rb, line 15
def minor
        @minor
end
patch() click to toggle source

Gets the number patch of version @return [integer] Patch number of version

# File lib/kxi/application/version.rb, line 21
def patch
        @patch
end
to_s() click to toggle source

Converts class to string representation @return [string] String representation of class

# File lib/kxi/application/version.rb, line 53
def to_s
        "#{@major}.#{@minor}.#{@patch}#{@id == nil ? '' : "-#{@id}"}#{@meta == nil ? '' : "+#{@meta}"}"
end