Class: Version

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/coderunner/version.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version = "") ⇒ Version

Returns a new instance of Version.



6
7
8
9
10
11
12
# File 'lib/coderunner/version.rb', line 6

def initialize(version="")
  v = version.split(".")
  @major = v[0].to_i
  @feature_group = v[1] ? v[1].to_i : 0
  @feature = v[2] ? v[2].to_i : 0
  @bugfix = v[2] ? v[3].to_i : 0
end

Instance Attribute Details

#bugfixObject (readonly)

Returns the value of attribute bugfix.



4
5
6
# File 'lib/coderunner/version.rb', line 4

def bugfix
  @bugfix
end

#featureObject (readonly)

Returns the value of attribute feature.



4
5
6
# File 'lib/coderunner/version.rb', line 4

def feature
  @feature
end

#feature_groupObject (readonly)

Returns the value of attribute feature_group.



4
5
6
# File 'lib/coderunner/version.rb', line 4

def feature_group
  @feature_group
end

#majorObject (readonly)

Returns the value of attribute major.



4
5
6
# File 'lib/coderunner/version.rb', line 4

def major
  @major
end

Class Method Details

.sortObject



20
21
22
# File 'lib/coderunner/version.rb', line 20

def self.sort
  self.sort!{|a,b| a <=> b}
end

Instance Method Details

#<=>(other) ⇒ Object



14
15
16
17
18
19
# File 'lib/coderunner/version.rb', line 14

def <=>(other)
  return @major <=> other.major if ((@major <=> other.major) != 0)
  return @feature_group <=> other.feature_group if ((@feature_group <=> other.feature_group) != 0)
  return @feature <=> other.feature if ((@feature <=> other.feature) != 0)
  return @bugfix <=> other.bugfix
end

#to_sObject



24
25
26
# File 'lib/coderunner/version.rb', line 24

def to_s
  @major.to_s + "." + @feature_group.to_s + "." + @feature.to_s + "." + @bugfix.to_s
end