Class: Ports::Version
- Inherits:
-
Object
- Object
- Ports::Version
- Includes:
- Comparable
- Defined in:
- lib/port_upgrade/version.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(s) ⇒ Version
constructor
A new instance of Version.
Constructor Details
#initialize(s) ⇒ Version
Returns a new instance of Version.
5 6 7 |
# File 'lib/port_upgrade/version.rb', line 5 def initialize(s) @parts = breakup_version(s) end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
4 5 6 |
# File 'lib/port_upgrade/version.rb', line 4 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/port_upgrade/version.rb', line 9 def <=>(other) return 0 if @parts.nil? or other.parts.nil? $stderr.puts("self: #{@parts.inspect}") if $DEBUG $stderr.puts("other: #{other.parts.inspect}") if $DEBUG cmp = 0 numparts = @parts.size>other.parts.size ? @parts.size : other.parts.size 0.upto(numparts-1) do |i| p = i>=@parts.size ? ["-1"] : @parts[i] q = i>=other.parts.size ? ["-1"] : other.parts[i] numsubparts = p.size>q.size ? p.size : q.size 0.upto(numsubparts-1) do |j| r = j>=p.size ? "-1" : p[j] s = j>=q.size ? "-1" : q[j] $stderr.puts("p of #{j}: #{r}") if $DEBUG $stderr.puts("q of #{j}: #{s}") if $DEBUG a = r =~ /^-?[0-9]+$/ ? r.to_i : r b = s =~ /^-?[0-9]+$/ ? s.to_i : s $stderr.puts "#{a.inspect} <=> #{b.inspect}" if $DEBUG if a.instance_of?(b.class) cmp = a <=> b else $stderr.puts "Can't compare different classes #{a.class.to_s} <=> #{b.class.to_s}" if $DEBUG cmp = 0 end return cmp if cmp != 0 end return cmp if cmp != 0 end cmp end |