Class: EC2::Platform::Linux::Tar::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2/platform/linux/tar.rb

Direct Known Subclasses

Solaris::Tar::Version

Constant Summary collapse

'tar 1.15'
REGEX =
/(?:tar).*?(\d+)\.(\d+)\.?(\d*)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#stringObject

Returns the value of attribute string.



69
70
71
# File 'lib/ec2/platform/linux/tar.rb', line 69

def string
  @string
end

#valuesObject (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

.currentObject



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

#defaultObject



76
77
78
79
80
# File 'lib/ec2/platform/linux/tar.rb', line 76

def default
  s = `#{Command.new.version.expand}`.strip
  s = nil unless $? == 0
  s
end

#usable?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/ec2/platform/linux/tar.rb', line 96

def usable?
   self >= Version.new(Version::RECOMMENDED)
end