Class: Serverspec::Type::Package::Version
- Inherits:
-
Object
- Object
- Serverspec::Type::Package::Version
- Includes:
- Comparable
- Defined in:
- lib/serverspec/type/package.rb
Instance Attribute Summary collapse
-
#epoch ⇒ Object
readonly
Returns the value of attribute epoch.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(val) ⇒ Version
constructor
A new instance of Version.
- #ver_array ⇒ Object
Constructor Details
#initialize(val) ⇒ Version
Returns a new instance of Version.
32 33 34 35 36 37 38 39 |
# File 'lib/serverspec/type/package.rb', line 32 def initialize(val) matches = val.match(/^(?:(\d+):)?(\d[0-9a-zA-Z.+:~-]*)$/) if matches.nil? raise ArgumentError, "Malformed version number string #{val}" end @epoch = matches[1].to_i @version = matches[2].to_s end |
Instance Attribute Details
#epoch ⇒ Object (readonly)
Returns the value of attribute epoch.
30 31 32 |
# File 'lib/serverspec/type/package.rb', line 30 def epoch @epoch end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
30 31 32 |
# File 'lib/serverspec/type/package.rb', line 30 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/serverspec/type/package.rb', line 41 def <=>(other) other = Version.new(other) if other.is_a?(String) rv = @epoch <=> other.epoch return rv if rv != 0 self.ver_array <=> other.ver_array end |
#ver_array ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/serverspec/type/package.rb', line 49 def ver_array val = @version re = /^(?:(\d+)|(\D+))(.*)$/ res = [] until val.empty? matches = val.match(re) if matches[1].nil? # String matches[2].to_s.each_byte do |b| code_point = defined?("~".ord) ? "~".ord : ?~ res << ((b == code_point) ? -2 : b) end else # Digits res << matches[1].to_i end val = matches[3].to_s end res << -1 end |