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.
32 33 34 35 36 37 |
# File 'lib/apt_control.rb', line 32 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.
25 26 27 |
# File 'lib/apt_control.rb', line 25 def bugfix @bugfix end |
#debian ⇒ Object (readonly)
Returns the value of attribute debian.
25 26 27 |
# File 'lib/apt_control.rb', line 25 def debian @debian end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
25 26 27 |
# File 'lib/apt_control.rb', line 25 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
25 26 27 |
# File 'lib/apt_control.rb', line 25 def minor @minor end |
Class Method Details
.parse(string) ⇒ Object
27 28 29 30 |
# File 'lib/apt_control.rb', line 27 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
43 44 45 |
# File 'lib/apt_control.rb', line 43 def <=>(rhs) self.to_a.compact <=> rhs.to_a.compact end |
#==(rhs) ⇒ Object
47 48 49 |
# File 'lib/apt_control.rb', line 47 def ==(rhs) self.to_a == rhs.to_a end |
#=~(rhs) ⇒ Object
51 52 53 |
# File 'lib/apt_control.rb', line 51 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
59 60 61 62 63 64 |
# File 'lib/apt_control.rb', line 59 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
68 69 70 71 72 |
# File 'lib/apt_control.rb', line 68 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
75 76 77 78 79 80 81 82 83 |
# File 'lib/apt_control.rb', line 75 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
39 40 41 |
# File 'lib/apt_control.rb', line 39 def to_a [@major, @minor, @bugfix, @debian] end |
#to_s ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/apt_control.rb', line 85 def to_s [ "#{major}.#{minor}", bugfix && ".#{bugfix}", debian && "-#{debian}" ].compact.join end |