Class: Relix::Version

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



9
10
11
12
13
# File 'lib/relix/version.rb', line 9

def initialize(version)
  @major, @minor, @patch = version.to_s.split(".").collect{|e| e.to_i}
  @minor ||= 0
  @patch ||= 0
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



8
9
10
# File 'lib/relix/version.rb', line 8

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



8
9
10
# File 'lib/relix/version.rb', line 8

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



8
9
10
# File 'lib/relix/version.rb', line 8

def patch
  @patch
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/relix/version.rb', line 15

def <=>(other)
  case other
  when String
    (self <=> Version.new(other))
  else
    if((r = (major <=> other.major)) != 0)
      r
    elsif((r = (minor <=> other.minor)) != 0)
      r
    else
      (patch <=> other.patch)
    end
  end
end