class MyPrecious::PyPackageInfo::Requirement

Representation of a single requirement clause

Attributes

op[R]
vernum[R]

Public Class Methods

new(op, vernum) click to toggle source
Calls superclass method
# 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

Public Instance Methods

determinative?() click to toggle source
# File lib/myprecious/python_packages.rb, line 492
def determinative?
  [:==, :str_equal].include?(op)
end
satisfied_by?(version, strict: true) click to toggle source

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.

# 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

Private Instance Methods

comp_keys(other) click to toggle source
# File lib/myprecious/python_packages.rb, line 525
def comp_keys(other)
  [self.vernum, other].map {|v| PyPackageInfo.parse_version_str(v)}
end
series(comp_key) click to toggle source
# File lib/myprecious/python_packages.rb, line 529
def series(comp_key)
  comp_key.dup.tap do |result|
    result.final.to_series
  end
end