class Monsoon::SemVer
Attributes
major[R]
minor[R]
patch[R]
Public Class Methods
new(version)
click to toggle source
# File lib/monsoon/sem_ver.rb, line 7 def initialize(version) version = version.to_s if version.is_a?(Symbol) raise ArgumentError, 'Not a valid semantic version' unless self.class.valid?(version) ver = version.split('.') @major = ver[0].to_i @minor = ver[1].to_i @patch = ver[2].to_i end
valid?(version)
click to toggle source
# File lib/monsoon/sem_ver.rb, line 26 def self.valid?(version) version = version.to_s if version.is_a?(Symbol) version.is_a?(String) && version.split('.').take(3).map(&:to_i).reduce(0, :+) > 0 end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/monsoon/sem_ver.rb, line 17 def <=> (other) other = self.class.new(other) if self.class.valid?(other) [major, minor, patch] <=> [other.major, other.minor, other.patch] if other.is_a?(self.class) end
to_s()
click to toggle source
# File lib/monsoon/sem_ver.rb, line 22 def to_s "#{major}.#{minor}.#{patch}" end