Class: Vim::Flavor::VersionConstraint
- Inherits:
-
Object
- Object
- Vim::Flavor::VersionConstraint
- Defined in:
- lib/vim-flavor/versionconstraint.rb
Instance Attribute Summary collapse
-
#base_version ⇒ Object
readonly
Returns the value of attribute base_version.
-
#qualifier ⇒ Object
readonly
Specifies how to choose a suitable version according to base_version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #compatible?(other_version_or_s) ⇒ Boolean
- #find_the_best_version(versions) ⇒ Object
-
#initialize(s) ⇒ VersionConstraint
constructor
A new instance of VersionConstraint.
- #to_s ⇒ Object
Constructor Details
#initialize(s) ⇒ VersionConstraint
Returns a new instance of VersionConstraint.
9 10 11 |
# File 'lib/vim-flavor/versionconstraint.rb', line 9 def initialize(s) @base_version, @qualifier = self.class.parse(s) end |
Instance Attribute Details
#base_version ⇒ Object (readonly)
Returns the value of attribute base_version.
4 5 6 |
# File 'lib/vim-flavor/versionconstraint.rb', line 4 def base_version @base_version end |
#qualifier ⇒ Object (readonly)
Specifies how to choose a suitable version according to base_version.
7 8 9 |
# File 'lib/vim-flavor/versionconstraint.rb', line 7 def qualifier @qualifier end |
Class Method Details
.parse(s) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/vim-flavor/versionconstraint.rb', line 22 def self.parse(s) m = /^\s*(>=|~>)\s+(\S+)$/.match(s) if m [Gem::Version.create(m[2]), m[1]] else raise "Invalid version constraint: #{s.inspect}" end end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 20 |
# File 'lib/vim-flavor/versionconstraint.rb', line 17 def ==(other) self.base_version == other.base_version && self.qualifier == other.qualifier end |
#compatible?(other_version_or_s) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vim-flavor/versionconstraint.rb', line 31 def compatible?(other_version_or_s) v = Gem::Version.create(other_version_or_s) if qualifier == '~>' self.base_version.bump() > v and v >= self.base_version elsif qualifier == '>=' v >= self.base_version else raise NotImplementedError end end |
#find_the_best_version(versions) ⇒ Object
42 43 44 45 46 |
# File 'lib/vim-flavor/versionconstraint.rb', line 42 def find_the_best_version(versions) versions. select {|v| compatible?(v)}. max() end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/vim-flavor/versionconstraint.rb', line 13 def to_s() "#{qualifier} #{base_version}" end |