Class: SemverCheck::Compare
- Inherits:
-
Object
- Object
- SemverCheck::Compare
- Includes:
- Comparable
- Defined in:
- lib/semver_check.rb
Overview
Class to compare SemVer strings
Constant Summary collapse
- SEMVER_PATTERN =
/\A (?<semver> (?<major>0|[1-9]\d*) \. (?<minor>0|[1-9]\d*) \. (?<patch>0|[1-9]\d*) (?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*) (?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*) )? (?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))? ) \Z/x
- MAPPING_TABLE =
[ %w[n 1], %w[sn 1], %w[ssn 1], %w[o -1], %w[so -1], %w[sso -1], %w[sss 0] ].freeze
- ORDER =
%i[major minor patch prerelease].freeze
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Compare
constructor
A new instance of Compare.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Compare
Returns a new instance of Compare.
39 40 41 |
# File 'lib/semver_check.rb', line 39 def initialize(version) @version = prepare_version(version) end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
37 38 39 |
# File 'lib/semver_check.rb', line 37 def version @version end |
Instance Method Details
#!=(other) ⇒ Object
49 50 51 |
# File 'lib/semver_check.rb', line 49 def !=(other) [-1, 1].include?(self.<=>(other)) end |
#<=>(other) ⇒ Object
43 44 45 46 47 |
# File 'lib/semver_check.rb', line 43 def <=>(other) return nil unless other.is_a? Compare comparison(other) end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/semver_check.rb', line 53 def to_s @version[:semver] end |