Module: Monkey::Version

Defined in:
lib/monkey/version.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(value = "") ⇒ Object



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

def self.new(value = "")
  super.to_version!
end

Instance Method Details

#<=>(other) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/monkey/version.rb', line 19

def <=>(other)
  return super unless other.respond_to? :to_version
  mine, others = fields.dup, other.to_version.fields
  loop do
    a, b = mine.unshift, others.unshift
    return  0 if a.nil? and b.nil?
    return  1 if b.nil? or (a.is_a? Integer and b.is_a? String)
    return -1 if a.nil? or (b.is_a? Integer and a.is_a? String)
    return comp unless (comp = (a <=> b)) == 0
  end
end

#fieldsObject



31
32
33
# File 'lib/monkey/version.rb', line 31

def fields
  split(".").map { |f| f =~ /^\d+$/ ? f.to_i : f }
end

#majorObject



15
# File 'lib/monkey/version.rb', line 15

def major; fields[0]; end

#minorObject



16
# File 'lib/monkey/version.rb', line 16

def minor; fields[1]; end

#tinyObject



17
# File 'lib/monkey/version.rb', line 17

def tiny;  fields[2]; end

#to_versionObject



7
8
9
# File 'lib/monkey/version.rb', line 7

def to_version
  self.dup
end

#to_version!Object



11
12
13
# File 'lib/monkey/version.rb', line 11

def to_version!
  self
end