class Epuber::Version
Attributes
segments[R]
version[R]
Public Class Methods
correct?(version)
click to toggle source
True if the version
string matches RubyGems' requirements.
# File lib/epuber/vendor/version.rb, line 17 def self.correct?(version) version.to_s =~ VERSION_RE end
new(version)
click to toggle source
@param [String, Numeric] version input primitive value for version
# File lib/epuber/vendor/version.rb, line 26 def initialize(version) unless self.class.correct?(version) raise StandardError, "Malformed version number string #{version}" end @version = version.to_s.strip end
Public Instance Methods
<=>(other)
click to toggle source
Compares this version with other
returning -1, 0, or 1 if the other version is larger, the same, or smaller than this one.
@return [Numeric]
# File lib/epuber/vendor/version.rb, line 54 def <=>(other) return unless other.is_a?(Version) || other.is_a?(String) || other.is_a?(Float) || other.is_a?(Integer) other = other.is_a?(Version) ? other : Version.new(other) return 0 if @version == other.version lhsegments = segments rhsegments = other.segments lhsize = lhsegments.size rhsize = rhsegments.size limit = (lhsize > rhsize ? lhsize : rhsize) - 1 i = 0 while i <= limit lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0 i += 1 next if lhs == rhs return -1 if lhs.is_a?(String) && is_number(rhs) return 1 if is_number(lhs) && rhs.is_a?(String) return lhs <=> rhs end 0 end
to_s()
click to toggle source
@return [String]
# File lib/epuber/vendor/version.rb, line 44 def to_s "#{segments.join('.')}" end