Class: MyPrecious::PyPackageInfo::Version
- Inherits:
-
Object
- Object
- MyPrecious::PyPackageInfo::Version
- Includes:
- Comparable
- Defined in:
- lib/myprecious/python_packages.rb
Overview
Represents a full PEP-440 version
Constant Summary collapse
- NOT_PRE =
['z', 0]
Instance Method Summary collapse
- #<=>(rhs) ⇒ Object
-
#initialize(final, epoch: 0, pre: [], post: nil, dev: nil, local: nil) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #pre_group ⇒ Object
- #pre_num ⇒ Object
- #prerelease? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(final, epoch: 0, pre: [], post: nil, dev: nil, local: nil) ⇒ Version
Returns a new instance of Version.
581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/myprecious/python_packages.rb', line 581 def initialize(final, epoch: 0, pre: [], post: nil, dev: nil, local: nil) @epoch = (epoch || 0).to_i @final = final.kind_of?(FinalVersion) ? final : FinalVersion.new(final) @pre = normalize_part(pre[1]) {|n| n && [pre[0], n]} @post = normalize_part(post) {|n| n && [n] } @dev = normalize_part(dev) {|n| n} @local = case local when nil then nil when Array then local else local.to_s.split(/[._-]/).map {|part| try_to_i(part)} end end |
Instance Method Details
#<=>(rhs) ⇒ Object
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/myprecious/python_packages.rb', line 618 def <=>(rhs) return nil unless rhs.kind_of?(self.class) steps = Enumerator.new do |comps| %i[epoch final pre_comp post_comp dev_comp].each do |attr| comps << (send(attr) <=> rhs.send(attr)) end case [local, rhs.local].count(&:nil?) when 2 then comps << 0 when 1 then comps << (local.nil? ? -1 : 1) else comps << (local <=> rhs.local) end end steps.find {|v| v != 0} || 0 end |
#inspect ⇒ Object
595 596 597 |
# File 'lib/myprecious/python_packages.rb', line 595 def inspect "#<#{self.class.name} #{to_s.inspect}>" end |
#pre_group ⇒ Object
610 611 612 |
# File 'lib/myprecious/python_packages.rb', line 610 def pre_group @pre && @pre[0] end |
#pre_num ⇒ Object
614 615 616 |
# File 'lib/myprecious/python_packages.rb', line 614 def pre_num @pre && @pre[1] end |
#prerelease? ⇒ Boolean
635 636 637 |
# File 'lib/myprecious/python_packages.rb', line 635 def prerelease? !!(@pre || @dev) end |
#to_s ⇒ Object
599 600 601 602 603 604 605 606 607 608 |
# File 'lib/myprecious/python_packages.rb', line 599 def to_s [].tap do |parts| parts << "#{epoch}!" unless epoch == 0 parts << final.to_s parts << "#{@pre[0]}#{@pre[1]}" if @pre parts << ".post#{@post}" if @post parts << ".dev#{@dev}" if @dev parts << "+#{local}" if local end.join('') end |