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.



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

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



716
717
718
719
720
721
722
723
724
# File 'lib/myprecious/python_packages.rb', line 716

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



695
696
697
# File 'lib/myprecious/python_packages.rb', line 695

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

#each(&blk) ⇒ Object



703
704
705
# File 'lib/myprecious/python_packages.rb', line 703

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

#inspectObject



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

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

#lengthObject



699
700
701
# File 'lib/myprecious/python_packages.rb', line 699

def length
  @value.length
end

#to_sObject



708
709
710
# File 'lib/myprecious/python_packages.rb', line 708

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

#to_seriesObject



727
728
729
730
731
# File 'lib/myprecious/python_packages.rb', line 727

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