Class: OSGi::VersionRange

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

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#maxObject

Returns the value of attribute max.



87
88
89
# File 'lib/buildr4osgi/osgi/version.rb', line 87

def max
  @max
end

#max_inclusiveObject

Returns the value of attribute max_inclusive.



87
88
89
# File 'lib/buildr4osgi/osgi/version.rb', line 87

def max_inclusive
  @max_inclusive
end

#max_infiniteObject

Returns the value of attribute max_infinite.



87
88
89
# File 'lib/buildr4osgi/osgi/version.rb', line 87

def max_infinite
  @max_infinite
end

#minObject

Returns the value of attribute min.



87
88
89
# File 'lib/buildr4osgi/osgi/version.rb', line 87

def min
  @min
end

#min_inclusiveObject

Returns the value of attribute min_inclusive.



87
88
89
# File 'lib/buildr4osgi/osgi/version.rb', line 87

def min_inclusive
  @min_inclusive
end

Class Method Details

.parse(string, max_infinite = false) ⇒ Object

Parses a string into a VersionRange. Returns false if the string could not be parsed.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/buildr4osgi/osgi/version.rb', line 92

def self.parse(string, max_infinite = false)
  return string if string.is_a?(VersionRange) || string.is_a?(Version)
  if !string.nil? && (match = string.match /\s*([\[|\(])([0-9|A-z|\.]*)\s*,\s*([0-9|A-z|\.]*)([\]|\)])/)
    range = VersionRange.new
    range.min = Version.new(match[2])
    range.max = Version.new(match[3])
    range.min_inclusive = match[1] == '['
    range.max_inclusive = match[4] == ']'
    range
  elsif (!string.nil? && max_infinite  && string.match(/[0-9|\.]*/))
    range = VersionRange.new
    range.min = Version.new(string)
    range.max = nil
    range.min_inclusive = true
    range.max_infinite = true
    range
  else
    false
  end
end

Instance Method Details

#in_range(version) ⇒ Object

Returns true if the version is in the range of this VersionRange object. Uses OSGi versioning rules to determine if the version is in range.



120
121
122
123
124
125
126
127
128
# File 'lib/buildr4osgi/osgi/version.rb', line 120

def in_range(version)
  return in_range(version.min) && (version.max_infinite ? true : in_range(version.max)) if version.is_a?(VersionRange)
    
  result = min_inclusive ? min <= version : min < version
  if (!max_infinite)
    result &= max_inclusive ? max >= version : max > version
  end
  result
end

#to_sObject

:nodoc:



113
114
115
# File 'lib/buildr4osgi/osgi/version.rb', line 113

def to_s #:nodoc:
  "#{ min_inclusive ? '[' : '('}#{min},#{max_infinite ? "infinite" : max}#{max_inclusive ? ']' : ')'}"
end