class Chef::Version
Attributes
Public Class Methods
Source
# File lib/chef/version_class.rb, line 23 def initialize(str = "") parse(str) end
Public Instance Methods
Source
# File lib/chef/version_class.rb, line 35 def <=>(other) %i{major minor patch}.each do |method| version = send(method) begin ans = (version <=> other.send(method)) rescue NoMethodError # if the other thing isn't a version object, return nil return nil end return ans unless ans == 0 end 0 end
Source
# File lib/chef/version_class.rb, line 55 def eql?(other) other.is_a?(Version) && self == other end
For hash
Source
# File lib/chef/version_class.rb, line 48 def hash # Didn't put any thought or research into this, probably can be # done better to_s.hash end
Source
# File lib/chef/version_class.rb, line 27 def inspect "#{@major}.#{@minor}.#{@patch}" end
Source
# File lib/chef/version_class.rb, line 31 def to_s "#{@major}.#{@minor}.#{@patch}" end
Protected Instance Methods
Source
# File lib/chef/version_class.rb, line 61 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 msg = "'#{str}' does not match 'x.y.z' or 'x.y'" raise Chef::Exceptions::InvalidCookbookVersion.new( msg ) end end