module BeanStalk::Worker::Version

Attributes

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

Public Class Methods

new(str="") click to toggle source
# File lib/beanstalk-worker/version_class.rb, line 7
def initialize(str="")
  parse(str)
end

Public Instance Methods

<=>(v) click to toggle source
# File lib/beanstalk-worker/version_class.rb, line 19
def <=>(v)
  [:major, :minor, :patch].each do |method|
    ans = (self.send(method) <=> v.send(method))
    return ans if ans != 0
  end
  0
end
eql?(other) click to toggle source

For hash

# File lib/beanstalk-worker/version_class.rb, line 32
def eql?(other)
  other.is_a?(Version) && self == other
end
hash() click to toggle source
# File lib/beanstalk-worker/version_class.rb, line 27
def hash
  to_s.hash
end
inspect() click to toggle source
# File lib/beanstalk-worker/version_class.rb, line 11
def inspect
  "#{@major}.#{@minor}.#{@patch}"
end
to_s() click to toggle source
# File lib/beanstalk-worker/version_class.rb, line 15
def to_s
  "#{@major}.#{@minor}.#{@patch}"
end

Protected Instance Methods

parse(str="") click to toggle source
# File lib/beanstalk-worker/version_class.rb, line 38
def parse(str="")
  @major, @minor, @patch =
    case str.to_s
    when /^(\d+)\.(\d+)\.(\d+)$/
      [ $1.to_i, $2.to_i, $3.to_i ]
    when /^(\d+)\.(\d+)$/
      [ $1.to_i, $2.to_i, 0 ]
    else
      "'#{str.to_s}' does not match 'x.y.z' or 'x.y'"
    end
end