Class: OSGi::Version

Inherits:
Object show all
Defined in:
lib/buildr4osgi/osgi/version.rb

Overview

A class to represent OSGi versions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Version

:nodoc:



25
26
27
28
29
30
31
32
33
34
# File 'lib/buildr4osgi/osgi/version.rb', line 25

def initialize(string) #:nodoc:
  digits = string.gsub(/\"/, '').split(".")
  @major = digits[0]
  @minor = digits[1]
  @tiny = digits[2]
  @qualifier = digits[3]
  raise "Invalid version: " + self.to_s if @major == ""
  raise "Invalid version: " + self.to_s if @minor == "" && (!@tiny != "" || !@qualifier != "")
  raise "Invalid version: " + self.to_s if @tiny == "" && !@qualifier != ""
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



23
24
25
# File 'lib/buildr4osgi/osgi/version.rb', line 23

def major
  @major
end

#minorObject

Returns the value of attribute minor.



23
24
25
# File 'lib/buildr4osgi/osgi/version.rb', line 23

def minor
  @minor
end

#qualifierObject

Returns the value of attribute qualifier.



23
24
25
# File 'lib/buildr4osgi/osgi/version.rb', line 23

def qualifier
  @qualifier
end

#tinyObject

Returns the value of attribute tiny.



23
24
25
# File 'lib/buildr4osgi/osgi/version.rb', line 23

def tiny
  @tiny
end

Instance Method Details

#<(other) ⇒ Object

:nodoc:



64
65
66
# File 'lib/buildr4osgi/osgi/version.rb', line 64

def <(other) #:nodoc:
  (self.<=>(other)) == -1
end

#<=(other) ⇒ Object

:nodoc:



76
77
78
# File 'lib/buildr4osgi/osgi/version.rb', line 76

def <=(other) #:nodoc:
  (self.==(other)) || (self.<(other))
end

#<=>(other) ⇒ Object

:nodoc:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/buildr4osgi/osgi/version.rb', line 45

def <=>(other) #:nodoc:
  if other.is_a? String
    other = Version.new(other)
  elsif other.nil?
    return 1
  end

  [:major, :minor, :tiny, :qualifier].each do |digit|
    return 0 if send(digit).nil? or other.send(digit).nil?

    comparison = send(digit) <=> other.send(digit)
    if comparison != 0
      return comparison
    end

  end
  return 0
end

#==(other) ⇒ Object

:nodoc:



72
73
74
# File 'lib/buildr4osgi/osgi/version.rb', line 72

def ==(other) #:nodoc:
  (self.<=>(other)) == 0
end

#>(other) ⇒ Object

:nodoc:



68
69
70
# File 'lib/buildr4osgi/osgi/version.rb', line 68

def >(other) #:nodoc:
  (self.<=>(other)) == 1
end

#>=(other) ⇒ Object

:nodoc:



80
81
82
# File 'lib/buildr4osgi/osgi/version.rb', line 80

def >=(other) #:nodoc:
  (self.==(other)) || (self.>(other))
end

#to_sObject

:nodoc:



37
38
39
40
41
42
43
# File 'lib/buildr4osgi/osgi/version.rb', line 37

def to_s #:nodoc:
  str = [major]
  str << minor if minor
  str << tiny if minor && tiny
  str << qualifier if minor && tiny && qualifier
  str.compact.join(".")
end