class Bringit::VersionInfo

Attributes

major[R]
minor[R]
patch[R]

Public Class Methods

new(major = 0, minor = 0, patch = 0) click to toggle source
# File lib/bringit/version_info.rb, line 15
def initialize(major = 0, minor = 0, patch = 0)
  @major = major
  @minor = minor
  @patch = patch
end
parse(str) click to toggle source
# File lib/bringit/version_info.rb, line 7
def self.parse(str)
  if str && m = str.match(/(\d+)\.(\d+)\.(\d+)/)
    VersionInfo.new(m[1].to_i, m[2].to_i, m[3].to_i)
  else
    VersionInfo.new
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/bringit/version_info.rb, line 21
def <=>(other)
  return unless other.is_a? VersionInfo
  return unless valid? && other.valid?

  if other.major < @major
    1
  elsif @major < other.major
    -1
  elsif other.minor < @minor
    1
  elsif @minor < other.minor
    -1
  elsif other.patch < @patch
    1
  elsif @patch < other.patch
    -1
  else
    0
  end
end
to_s() click to toggle source
# File lib/bringit/version_info.rb, line 42
def to_s
  if valid?
    "%d.%d.%d" % [@major, @minor, @patch]
  else
    "Unknown"
  end
end
valid?() click to toggle source
# File lib/bringit/version_info.rb, line 50
def valid?
  @major >= 0 && @minor >= 0 && @patch >= 0 && @major + @minor + @patch > 0
end