Class: SimpleVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_version.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, micro) ⇒ SimpleVersion

Returns a new instance of SimpleVersion.



5
6
7
8
9
# 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

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



3
4
5
# File 'lib/simple_version.rb', line 3

def major
  @major
end

#microObject (readonly)

Returns the value of attribute micro.



3
4
5
# File 'lib/simple_version.rb', line 3

def micro
  @micro
end

#minorObject (readonly)

Returns the value of attribute minor.



3
4
5
# File 'lib/simple_version.rb', line 3

def minor
  @minor
end

Class Method Details

.parse(version_string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# 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

Instance Method Details

#<=>(other) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# 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_majorObject



22
23
24
# File 'lib/simple_version.rb', line 22

def next_major
  SimpleVersion.new(major+1, 0, 0)
end

#next_microObject



30
31
32
# File 'lib/simple_version.rb', line 30

def next_micro
  SimpleVersion.new(major, minor, micro+1)
end

#next_minorObject



26
27
28
# File 'lib/simple_version.rb', line 26

def next_minor
  SimpleVersion.new(major, minor+1, 0)
end

#to_sObject



34
35
36
# File 'lib/simple_version.rb', line 34

def to_s
  "%s.%s.%s" % [major, minor, micro]
end