Class: CKEditor5::Rails::Semver

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ckeditor5/rails/semver.rb

Constant Summary collapse

SEMVER_PATTERN =
/\A\d+\.\d+\.\d+\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#majorObject (readonly)

Returns the value of attribute major.



8
9
10
# File 'lib/ckeditor5/rails/semver.rb', line 8

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



8
9
10
# File 'lib/ckeditor5/rails/semver.rb', line 8

def minor
  @minor
end

#patchObject (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

Returns:

  • (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

#versionObject Also known as: to_s



33
34
35
# File 'lib/ckeditor5/rails/semver.rb', line 33

def version
  "#{major}.#{minor}.#{patch}"
end