class SimpleVersion
Attributes
major[R]
micro[R]
minor[R]
Public Class Methods
new(major, minor, micro)
click to toggle source
# File lib/simple_version.rb, line 5 def initialize(major, minor, micro) @major = to_integer(major) @minor = to_integer(minor) @micro = to_integer(micro) end
parse(version_string)
click to toggle source
# File lib/simple_version.rb, line 11 def SimpleVersion.parse(version_string) if version_string.to_s.strip == "" raise "version_string cannot be blank" end pieces = version_string.split(".", 3) if pieces.size != 3 raise "version must have 3 pieces" end SimpleVersion.new(pieces[0], pieces[1], pieces[2]) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/simple_version.rb, line 38 def <=>(other) value = major <=> other.major if value == 0 value = minor <=> other.minor if value == 0 value = micro <=> other.micro end end value end
next_major()
click to toggle source
# File lib/simple_version.rb, line 22 def next_major SimpleVersion.new(major+1, 0, 0) end
next_micro()
click to toggle source
# File lib/simple_version.rb, line 30 def next_micro SimpleVersion.new(major, minor, micro+1) end
next_minor()
click to toggle source
# File lib/simple_version.rb, line 26 def next_minor SimpleVersion.new(major, minor+1, 0) end
to_s()
click to toggle source
# File lib/simple_version.rb, line 34 def to_s "%s.%s.%s" % [major, minor, micro] end
Private Instance Methods
to_integer(value)
click to toggle source
# File lib/simple_version.rb, line 50 def to_integer(value) if value.to_s.match(/^\d+$/) value.to_i else raise "Value[%s] is not an integer" % value end end