class HtmlConditionalComment::VersionVector

Constants

DIGIT
DOT

Attributes

string[RW]

Public Class Methods

new(string) click to toggle source
# File lib/html-conditional-comment/version_vector.rb, line 10
def initialize(string)
  @string = nil
  @string = string.to_s() unless string.nil?()
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/html-conditional-comment/version_vector.rb, line 15
def <=>(other)
  #Force comparison class
  other = VersionVector.new(other) unless other.is_a?(VersionVector)

  return 0 if @string.nil?() || other.string.nil?()
  return 0 if @string == other.string

  #Normalize version array sizes
  left, right = self.to_a(), other.to_a()
  size = [left.size(), right.size()].min()
  left.slice!(size..-1)
  right.slice!(size..-1)

  #Compare based on number
  left.join.to_f() <=> right.join.to_f()
end
to_a() click to toggle source

Split string into array of version numbers, major can be multiple digits, minor can only be a single digit

# File lib/html-conditional-comment/version_vector.rb, line 36
def to_a()
  major, minors = @string.split(DOT)
  versions = (minors || '').scan(DIGIT)
  versions.unshift(major, '.')
  versions
end