Class: KXI::Application::VersionExpression
- Inherits:
-
Object
- Object
- KXI::Application::VersionExpression
- Defined in:
- lib/kxi/application/version_expression.rb
Overview
Represents a comparison of two semantic versions
Constant Summary collapse
- COMP_EQ =
Equivalence comparison
'='
- COMP_LEQ =
Less than or equivalent to comparison
'<='
- COMP_LT =
Less than comparison
'<'
- COMP_GEQ =
Grater than or equivalent to comparison
'>='
- COMP_GT =
Grater than comparison
'>'
- COMP_AT =
Minimal requirement comparison
'~>'
Class Method Summary collapse
-
.parse(str) ⇒ KXI::Application::VersionExpression
Parses a version expression from its string form.
Instance Method Summary collapse
-
#comparison ⇒ string
Get the comparison of versions.
-
#initialize(comp, major, minor = nil, patch = nil) ⇒ VersionExpression
constructor
Instantiates the VersionExpression class.
-
#major ⇒ int
Gets the major number of left-side version.
-
#matches?(ver) ⇒ bool
Checks whether expression is true for given version.
-
#minor ⇒ int?
Gets the minor number of left-side version.
-
#patch ⇒ int?
Gets the patch number of left-side version.
Constructor Details
#initialize(comp, major, minor = nil, patch = nil) ⇒ VersionExpression
Instantiates the KXI::Application::VersionExpression class
49 50 51 52 53 54 55 |
# 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 |
Class Method Details
.parse(str) ⇒ KXI::Application::VersionExpression
Parses a version expression from its string form
88 89 90 91 92 |
# 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 |
Instance Method Details
#comparison ⇒ string
Get the comparison of versions
22 23 24 |
# File 'lib/kxi/application/version_expression.rb', line 22 def comparison @comp end |
#major ⇒ int
Gets the major number of left-side version
28 29 30 |
# File 'lib/kxi/application/version_expression.rb', line 28 def major @major end |
#matches?(ver) ⇒ bool
Checks whether expression is true for given version
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 |
#minor ⇒ int?
Gets the minor number of left-side version
34 35 36 |
# File 'lib/kxi/application/version_expression.rb', line 34 def minor @minor end |
#patch ⇒ int?
Gets the patch number of left-side version
40 41 42 |
# File 'lib/kxi/application/version_expression.rb', line 40 def patch @patch end |