class Changelog::SemanticVersion
Constants
- VERSION_REGEX
Public Class Methods
new(version_string)
click to toggle source
Calls superclass method
# File lib/changelog/semantic_version.rb, line 11 def initialize(version_string) super(version_string) if valid? && extract_from_version(:patch, fallback: nil).nil? super(to_patch) end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/changelog/semantic_version.rb, line 27 def <=>(other) return nil unless other.is_a?(SemanticVersion) return 0 if self == other if major > other.major || (major >= other.major && minor > other.minor) || (major >= other.major && minor >= other.minor && patch > other.patch) 1 else -1 end end
==(other)
click to toggle source
Calls superclass method
# File lib/changelog/semantic_version.rb, line 19 def ==(other) if other.respond_to?(:to_patch) to_patch.eql?(other.to_patch) else super end end
major()
click to toggle source
# File lib/changelog/semantic_version.rb, line 40 def major @major ||= extract_from_version(:major).to_i end
minor()
click to toggle source
# File lib/changelog/semantic_version.rb, line 44 def minor @minor ||= extract_from_version(:minor).to_i end
patch()
click to toggle source
# File lib/changelog/semantic_version.rb, line 48 def patch @patch ||= extract_from_version(:patch).to_i end
to_minor()
click to toggle source
# File lib/changelog/semantic_version.rb, line 52 def to_minor "#{major}.#{minor}" end
to_patch()
click to toggle source
# File lib/changelog/semantic_version.rb, line 56 def to_patch "#{major}.#{minor}.#{patch}" end
valid?()
click to toggle source
# File lib/changelog/semantic_version.rb, line 61 def valid? self.class::VERSION_REGEX.match?(self) end
Private Instance Methods
extract_from_version(part, fallback: 0)
click to toggle source
# File lib/changelog/semantic_version.rb, line 67 def extract_from_version(part, fallback: 0) match_data = self.class::VERSION_REGEX.match(self) if match_data && match_data.names.include?(part.to_s) && match_data[part] String.new(match_data[part]) else fallback end end