Class: AptControl::Version
- Inherits:
-
Object
- Object
- AptControl::Version
- Includes:
- Comparable
- Defined in:
- lib/apt_control.rb
Instance Attribute Summary collapse
-
#bugfix ⇒ Object
readonly
Returns the value of attribute bugfix.
-
#debian ⇒ Object
readonly
Returns the value of attribute debian.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(rhs) ⇒ Object
- #==(rhs) ⇒ Object
- #=~(rhs) ⇒ Object
-
#initialize(major, minor, bugfix, debian) ⇒ Version
constructor
A new instance of Version.
-
#satisfies_exactly(rhs) ⇒ Object
operator returns true if this version satisfies the given rule and version spec, where all parts of the version given match our parts.
-
#satisfies_loosely(rhs) ⇒ Object
>= operator returns true if this version is greater than or equal to the given version.
-
#satisfies_pessimisticly(rhs) ⇒ Object
~> operator.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(major, minor, bugfix, debian) ⇒ Version
Returns a new instance of Version.
24 25 26 27 28 29 |
# File 'lib/apt_control.rb', line 24 def initialize(major, minor, bugfix, debian) @major = major && major.to_i @minor = minor && minor.to_i @bugfix = bugfix && bugfix.to_i @debian = debian end |
Instance Attribute Details
#bugfix ⇒ Object (readonly)
Returns the value of attribute bugfix.
17 18 19 |
# File 'lib/apt_control.rb', line 17 def bugfix @bugfix end |
#debian ⇒ Object (readonly)
Returns the value of attribute debian.
17 18 19 |
# File 'lib/apt_control.rb', line 17 def debian @debian end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
17 18 19 |
# File 'lib/apt_control.rb', line 17 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
17 18 19 |
# File 'lib/apt_control.rb', line 17 def minor @minor end |
Class Method Details
.parse(string) ⇒ Object
19 20 21 22 |
# File 'lib/apt_control.rb', line 19 def self.parse(string) match = /([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(?:-(.+))?/.match(string) match && new(*(1..4).map { |i| match[i] }) or raise "could not parse #{string}" end |
Instance Method Details
#<=>(rhs) ⇒ Object
35 36 37 |
# File 'lib/apt_control.rb', line 35 def <=>(rhs) self.to_a.compact <=> rhs.to_a.compact end |
#==(rhs) ⇒ Object
39 40 41 |
# File 'lib/apt_control.rb', line 39 def ==(rhs) self.to_a == rhs.to_a end |
#=~(rhs) ⇒ Object
43 44 45 |
# File 'lib/apt_control.rb', line 43 def =~(rhs) self.to_a[0...3] == rhs.to_a[0...3] end |
#satisfies_exactly(rhs) ⇒ Object
operator
returns true if this version satisfies the given rule and version spec, where all parts of the version given match our parts. Not commutative, as 1.3.1.4 satisfies 1.3, but 1.3 does not satisfy 1.3.1.4
51 52 53 54 55 56 |
# File 'lib/apt_control.rb', line 51 def satisfies_exactly(rhs) rhs.to_a.compact.zip(self.to_a).each do |rhs_part, lhs_part| return false unless rhs_part == lhs_part end return true end |
#satisfies_loosely(rhs) ⇒ Object
>= operator returns true if this version is greater than or equal to the given version
60 61 62 63 64 |
# File 'lib/apt_control.rb', line 60 def satisfies_loosely(rhs) return true if satisfies_exactly(rhs) return true if (self.to_a.compact <=> rhs.to_a.compact) >= 0 return false end |
#satisfies_pessimisticly(rhs) ⇒ Object
~> operator
67 68 69 70 71 72 73 74 75 |
# File 'lib/apt_control.rb', line 67 def satisfies_pessimisticly(rhs) return false unless self.to_a[0...2] == rhs.to_a[0...2] lhs_half = self.to_a[2..-1] rhs_half = rhs.to_a[2..-1] (lhs_half.compact <=> rhs_half.compact) >= 0 end |
#to_a ⇒ Object
31 32 33 |
# File 'lib/apt_control.rb', line 31 def to_a [@major, @minor, @bugfix, @debian] end |
#to_s ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/apt_control.rb', line 77 def to_s [ "#{major}.#{minor}", bugfix && ".#{bugfix}", debian && "-#{debian}" ].compact.join end |