Class: Aurb::Base::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/aurb/base.rb

Overview

Compare package versions.

Version.new('1.0.0') < Version.new('2.0.0') # => true
Version.new('1.1-1') < Version.new('1.0-6') # => false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Version

Returns a new instance of Version.



40
41
42
# File 'lib/aurb/base.rb', line 40

def initialize(*args)
  @version = args.join('.').split(/\W+/).map &:to_i
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



38
39
40
# File 'lib/aurb/base.rb', line 38

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Object



44
45
46
47
48
49
# File 'lib/aurb/base.rb', line 44

def <=>(other)
  [self.version.size, other.version.size].max.times do |i|
    c = self.version[i] <=> other.version[i]
    return c if c != 0
  end
end