Class: MyPrecious::PyPackageInfo::Requirement
- Inherits:
-
Object
- Object
- MyPrecious::PyPackageInfo::Requirement
- Defined in:
- lib/myprecious/python_packages.rb
Overview
Representation of a single requirement clause
Instance Attribute Summary collapse
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#vernum ⇒ Object
readonly
Returns the value of attribute vernum.
Instance Method Summary collapse
- #determinative? ⇒ Boolean
-
#initialize(op, vernum) ⇒ Requirement
constructor
A new instance of Requirement.
-
#satisfied_by?(version, strict: true) ⇒ Boolean
Query if this requirement is satisfied by a particular version.
Constructor Details
#initialize(op, vernum) ⇒ Requirement
Returns a new instance of Requirement.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/myprecious/python_packages.rb', line 473 def initialize(op, vernum) super() @op = case op when '<' then :< when '<=' then :<= when '==' then :== when '>=' then :>= when '>' then :> when '!=' then :!= when '~=' then :compatible when '===' then :str_equal when Symbol then op else raise "Unknown requirement operator #{op.inspect}" end @vernum = vernum end |
Instance Attribute Details
#op ⇒ Object (readonly)
Returns the value of attribute op.
490 491 492 |
# File 'lib/myprecious/python_packages.rb', line 490 def op @op end |
#vernum ⇒ Object (readonly)
Returns the value of attribute vernum.
490 491 492 |
# File 'lib/myprecious/python_packages.rb', line 490 def vernum @vernum end |
Instance Method Details
#determinative? ⇒ Boolean
492 493 494 |
# File 'lib/myprecious/python_packages.rb', line 492 def determinative? [:==, :str_equal].include?(op) end |
#satisfied_by?(version, strict: true) ⇒ Boolean
Query if this requirement is satisfied by a particular version
When strict:
is false and the instance is an equality-type requirement (i.e. the op
is :== or :str_equal
), the result is always true
.
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/myprecious/python_packages.rb', line 502 def satisfied_by?(version, strict: true) req_key = PyPackageInfo.parse_version_str(self.vernum) cand_key = PyPackageInfo.parse_version_str(version) return true if !strict && %i[== str_equal].include?(op) return case op when :compatible req_key, cand_key = comp_keys(version) (cand_key <=> req_key) >= 0 && (cand_key <=> series(req_key)) == 0 when :str_equal self.vernum == version.to_s else req_key, cand_key = comp_keys(version) if comp_result = (cand_key <=> req_key) comp_result.send(op, 0) else warn("Cannot test #{cand_key.inspect} #{op} #{req_key} (<=> returned nil)") end end end |