Class: EC2::Platform::Linux::Tar::Version
- Inherits:
-
Object
- Object
- EC2::Platform::Linux::Tar::Version
- Defined in:
- lib/ec2/platform/linux/tar.rb
Direct Known Subclasses
Constant Summary collapse
- RECOMMENDED =
'tar 1.15'- REGEX =
/(?:tar).*?(\d+)\.(\d+)\.?(\d*)/
Instance Attribute Summary collapse
-
#string ⇒ Object
Returns the value of attribute string.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #>=(other) ⇒ Object
- #default ⇒ Object
-
#initialize(str = nil) ⇒ Version
constructor
A new instance of Version.
- #usable? ⇒ Boolean
Constructor Details
#initialize(str = nil) ⇒ Version
Returns a new instance of Version.
71 72 73 74 75 |
# File 'lib/ec2/platform/linux/tar.rb', line 71 def initialize(str=nil) @string = str @string = default if str.nil? or str.empty? @values = Version.parse @string end |
Instance Attribute Details
#string ⇒ Object
Returns the value of attribute string.
69 70 71 |
# File 'lib/ec2/platform/linux/tar.rb', line 69 def string @string end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
68 69 70 |
# File 'lib/ec2/platform/linux/tar.rb', line 68 def values @values end |
Class Method Details
.current ⇒ Object
117 118 119 |
# File 'lib/ec2/platform/linux/tar.rb', line 117 def self.current Version.new end |
.parse(str) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ec2/platform/linux/tar.rb', line 99 def self.parse(str) match = REGEX.match(str) return nil if match.nil? begin items = match.captures.collect do |cap| cap.sub!(/^0*/, "") case cap when "" num = 0 else num = Integer(cap) end end rescue ArgumentError return nil end items end |
Instance Method Details
#>=(other) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ec2/platform/linux/tar.rb', line 85 def >= (other) return nil if @values.nil? if other.nil? or not other.is_a? Version raise ArgumentError, "Cannot compare with invalid version #{other}" end @values.zip(other.values).each do |mine, others| return false if mine < others return true if mine > others end return true end |
#default ⇒ Object
76 77 78 79 80 |
# File 'lib/ec2/platform/linux/tar.rb', line 76 def default s = `#{Command.new.version.}`.strip s = nil unless $? == 0 s end |
#usable? ⇒ Boolean
96 97 98 |
# File 'lib/ec2/platform/linux/tar.rb', line 96 def usable? self >= Version.new(Version::RECOMMENDED) end |