Class: Chef::Version

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/chef/version_class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = "") ⇒ Version

Returns a new instance of Version.



23
24
25
# File 'lib/chef/version_class.rb', line 23

def initialize(str="")
  @major, @minor, @patch = parse(str)
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



21
22
23
# File 'lib/chef/version_class.rb', line 21

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



21
22
23
# File 'lib/chef/version_class.rb', line 21

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



21
22
23
# File 'lib/chef/version_class.rb', line 21

def patch
  @patch
end

Instance Method Details

#<=>(v) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/chef/version_class.rb', line 35

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) ⇒ Boolean

For hash

Returns:

  • (Boolean)


50
51
52
# File 'lib/chef/version_class.rb', line 50

def eql?(other)
  other.is_a?(Version) && self == other
end

#hashObject



43
44
45
46
47
# File 'lib/chef/version_class.rb', line 43

def hash
  # Didn't put any thought or research into this, probably can be
  # done better
  to_s.hash
end

#inspectObject



27
28
29
# File 'lib/chef/version_class.rb', line 27

def inspect
  "#{@major}.#{@minor}.#{@patch}"
end

#to_sObject



31
32
33
# File 'lib/chef/version_class.rb', line 31

def to_s
  "#{@major}.#{@minor}.#{@patch}"
end