Class: MyPrecious::PyPackageInfo::FinalVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/myprecious/python_packages.rb

Overview

Represents the “final” part of a PEP-440 version string

Instance Method Summary collapse

Constructor Details

#initialize(final_ver) ⇒ FinalVersion

Returns a new instance of FinalVersion.



673
674
675
676
677
678
# File 'lib/myprecious/python_packages.rb', line 673

def initialize(final_ver)
  @value = case final_ver
  when Array then final_ver
  else final_ver.split('.').map {|s| seg_value(s)}
  end
end

Instance Method Details

#<=>(rhs) ⇒ Object



701
702
703
704
705
706
707
708
709
# File 'lib/myprecious/python_packages.rb', line 701

def <=>(rhs)
  nil unless rhs.kind_of?(FinalVersion)
  (0..Float::INFINITY).lazy.each do |i|
    return 0 if self[i].nil? && rhs[i].nil?
    return 0 if [self[i], rhs[i]].include?(:*)
    diff = (self[i] || 0) <=> (rhs[i] || 0)
    return diff if diff != 0
  end
end

#[](n) ⇒ Object



680
681
682
# File 'lib/myprecious/python_packages.rb', line 680

def [](n)
  @value[n]
end

#each(&blk) ⇒ Object



688
689
690
# File 'lib/myprecious/python_packages.rb', line 688

def each(&blk)
  @value.each(&blk)
end

#inspectObject



697
698
699
# File 'lib/myprecious/python_packages.rb', line 697

def inspect
  "#<#{self.class.name} #{to_s}>"
end

#lengthObject



684
685
686
# File 'lib/myprecious/python_packages.rb', line 684

def length
  @value.length
end

#to_sObject



693
694
695
# File 'lib/myprecious/python_packages.rb', line 693

def to_s
  @value.join('.')
end

#to_seriesObject



712
713
714
715
716
# File 'lib/myprecious/python_packages.rb', line 712

def to_series
  self.class.new(@value.dup.tap do |mver|
    mver[-1] = :*
  end.join('.'))
end