class TingYun::Support::VersionNumber

Attributes

parts[R]

Public Class Methods

new(version_string) click to toggle source
# File lib/ting_yun/support/version_number.rb, line 11
def initialize(version_string)
  version_string ||= '1.0.0'
  @parts = version_string.split('.').map { |n| n =~ /^\d+$/ ? n.to_i : n }
end

Private Class Methods

compare(parts1, parts2) click to toggle source
# File lib/ting_yun/support/version_number.rb, line 47
def self.compare(parts1, parts2)
  a, b = parts1.first, parts2.first
  case
    when a.nil? && b.nil? then
      0
    when a.nil? then
      b.is_a?(Fixnum) ? -1 : 1
    when b.nil? then
      -compare(parts2, parts1)
    when a.to_s == b.to_s then
      compare(parts1[1..-1], parts2[1..-1])
    when a.is_a?(String) then
      b.is_a?(Fixnum) ? -1 : (a <=> b)
    when b.is_a?(String) then
      -compare(parts2, parts1)
    else # they are both fixnums, not nil
      a <=> b
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/ting_yun/support/version_number.rb, line 28
def <=>(other)
  other = self.class.new(other) if other.is_a? String
  self.class.compare(self.parts, other.parts)
end
eql?(other) click to toggle source
# File lib/ting_yun/support/version_number.rb, line 41
def eql? other
  (self <=> other) == 0
end
hash() click to toggle source
# File lib/ting_yun/support/version_number.rb, line 37
def hash
  @parts.hash
end
major_version() click to toggle source
# File lib/ting_yun/support/version_number.rb, line 16
def major_version;
  @parts[0];
end
minor_version() click to toggle source
# File lib/ting_yun/support/version_number.rb, line 20
def minor_version;
  @parts[1];
end
tiny_version() click to toggle source
# File lib/ting_yun/support/version_number.rb, line 24
def tiny_version;
  @parts[2];
end
to_s() click to toggle source
# File lib/ting_yun/support/version_number.rb, line 33
def to_s
  @parts.join(".")
end