class KXI::Application::VersionExpression
Represents a comparison of two semantic versions
Constants
- COMP_AT
Minimal requirement comparison
- COMP_EQ
Equivalence comparison
- COMP_GEQ
Grater than or equivalent to comparison
- COMP_GT
Grater than comparison
- COMP_LEQ
Less than or equivalent to comparison
- COMP_LT
Less than comparison
Public Class Methods
Instantiates the {KXI::Application::VersionExpression} class @param [string] comp Comparison rule of expression @param [int] major Major number of left-side version @param [int,nil] minor Minor number of left-side version @param [int,nil] patch Patch number of left-side version
# File lib/kxi/application/version_expression.rb, line 49 def initialize(comp, major, minor = nil, patch = nil) @comp = comp @major = major @minor = minor @patch = patch @target = KXI::Application::Version.new(major, minor == nil ? 0 : minor, patch == nil ? 0 : patch) end
Parses a version expression from its string form @param [string] str String representation of version expression @return [KXI::Application::VersionExpression] Version
expression equivalent to given string
# File lib/kxi/application/version_expression.rb, line 88 def self.parse(str) m = /^\s*(?'cm'>|<|>=|<=|=|~>)\s*(?'mj'\d+)\s*(\.\s*(?'mi'\d+))?\s*(\.\s*(?'pt'\d+))?\s*?$/m.match(str) raise(KXI::Exceptions::ParseException.new('version expression', str)) if m == nil return VersionExpression.new(m['cm'], m['mj'].to_i, m['mi']&.to_i, m['pt']&.to_i) end
Public Instance Methods
Get the comparison of versions @return [string] Comparison of versions
# File lib/kxi/application/version_expression.rb, line 22 def comparison @comp end
Gets the major number of left-side version @return [int] Major number version
# File lib/kxi/application/version_expression.rb, line 28 def major @major end
Checks whether expression is true for given version @param ver [KXI::Application::Version] Right-side version of expression @return [bool] True if expression is valid; otherwise false
# File lib/kxi/application/version_expression.rb, line 60 def matches?(ver) case @comp when COMP_EQ return ( ver.major == @major and ver.minor == (@minor == nil ? 0 : @minor) and ver.patch == (@patch == nil ? 0 : @patch) ) when COMP_AT return ( ver.major == @major and (@minor == nil or ver.minor == @minor) and (@patch == nil or ver.patch == @patch) ) when COMP_GEQ return ver >= @target when COMP_LEQ return ver <= @target when COMP_GT return ver > @target when COMP_LT return ver < @target end end
Gets the minor number of left-side version @return [int,nil] Minor number version
# File lib/kxi/application/version_expression.rb, line 34 def minor @minor end
Gets the patch number of left-side version @return [int,nil] Patch number version
# File lib/kxi/application/version_expression.rb, line 40 def patch @patch end