Class: TentD::TentVersion
- Inherits:
-
Object
- Object
- TentD::TentVersion
- Includes:
- Comparable
- Defined in:
- lib/tentd/tent_version.rb
Constant Summary collapse
- Infinity =
1 / 0.0
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version_string) ⇒ TentVersion
constructor
A new instance of TentVersion.
- #parts ⇒ Object
- #parts=(array) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version_string) ⇒ TentVersion
Returns a new instance of TentVersion.
11 12 13 |
# File 'lib/tentd/tent_version.rb', line 11 def initialize(version_string) @version = version_string end |
Class Method Details
.from_uri(uri) ⇒ Object
7 8 9 |
# File 'lib/tentd/tent_version.rb', line 7 def self.from_uri(uri) new((uri.to_s.match(/v([.\dx]+)/) || [])[1]) end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tentd/tent_version.rb', line 27 def <=>(other) other = self.class.new(other) if other.kind_of?(String) parts.each_with_index.map { |p, index| if (p == 'x' || other.parts[index] == 'x') || p == other.parts[index] 0 elsif p < other.parts[index] -1 elsif p > other.parts[index] 1 end }.each { |r| return r if r != 0 } 0 end |
#parts ⇒ Object
19 20 21 |
# File 'lib/tentd/tent_version.rb', line 19 def parts @version.split('.').map { |p| p == 'x' ? p : p.to_i } end |
#parts=(array) ⇒ Object
23 24 25 |
# File 'lib/tentd/tent_version.rb', line 23 def parts=(array) @version = array.join('.') end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/tentd/tent_version.rb', line 15 def to_s @version end |