2 # HTTPVersion.rb -- presentation of HTTP version
4 # Author: IPR -- Internet Programming with Ruby -- writers
5 # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
8 # $IPR: httpversion.rb,v 1.5 2002/09/21 12:23:37 gotoyuzo Exp $
14 attr_accessor :major, :minor
16 def self.convert(version)
17 version.is_a?(self) ? version : new(version)
20 def initialize(version)
23 @major, @minor = version.major, version.minor
25 if /^(\d+)\.(\d+)$/ =~ version
26 @major, @minor = $1.to_i, $2.to_i
29 if @major.nil? || @minor.nil?
31 format("cannot convert %s into %s", version.class, self.class)
36 unless other.is_a?(self.class)
37 other = self.class.new(other)
39 if (ret = @major <=> other.major) == 0
40 return @minor <=> other.minor
46 format("%d.%d", @major, @minor)