Class: CKEditor5::Rails::Semver
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Semver
- Includes:
- Comparable
- Defined in:
- lib/ckeditor5/rails/semver.rb
Constant Summary collapse
- SEMVER_PATTERN =
/\A\d+\.\d+\.\d+\z/
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version_string) ⇒ Semver
constructor
A new instance of Semver.
- #safe_update?(other_version) ⇒ Boolean
- #version ⇒ Object (also: #to_s)
Constructor Details
#initialize(version_string) ⇒ Semver
Returns a new instance of Semver.
12 13 14 15 |
# File 'lib/ckeditor5/rails/semver.rb', line 12 def initialize(version_string) validate!(version_string) @major, @minor, @patch = version_string.split('.').map(&:to_i) end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
8 9 10 |
# File 'lib/ckeditor5/rails/semver.rb', line 8 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
8 9 10 |
# File 'lib/ckeditor5/rails/semver.rb', line 8 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
8 9 10 |
# File 'lib/ckeditor5/rails/semver.rb', line 8 def patch @patch end |
Instance Method Details
#<=>(other) ⇒ Object
17 18 19 20 21 |
# File 'lib/ckeditor5/rails/semver.rb', line 17 def <=>(other) return nil unless other.is_a?(Semver) [major, minor, patch] <=> [other.major, other.minor, other.patch] end |
#safe_update?(other_version) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/ckeditor5/rails/semver.rb', line 23 def safe_update?(other_version) other = self.class.new(other_version) return false if other.major != major return true if other.minor > minor return true if other.minor == minor && other.patch > patch false end |
#version ⇒ Object Also known as: to_s
33 34 35 |
# File 'lib/ckeditor5/rails/semver.rb', line 33 def version "#{major}.#{minor}.#{patch}" end |