Fix up Rubinius specific library specs.
[rbx.git] / lib / webrick / httpversion.rb
blob86907a26bd7e01ae78b07f9e4baae4d1e99e5963
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
6 # reserved.
8 # $IPR: httpversion.rb,v 1.5 2002/09/21 12:23:37 gotoyuzo Exp $
10 module WEBrick
11   class HTTPVersion
12     include Comparable
14     attr_accessor :major, :minor
16     def self.convert(version)
17       version.is_a?(self) ? version : new(version)
18     end
20     def initialize(version)
21       case version
22       when HTTPVersion
23         @major, @minor = version.major, version.minor
24       when String
25         if /^(\d+)\.(\d+)$/ =~ version
26           @major, @minor = $1.to_i, $2.to_i
27         end
28       end
29       if @major.nil? || @minor.nil?
30         raise ArgumentError,
31           format("cannot convert %s into %s", version.class, self.class)
32       end
33     end
35     def <=>(other)
36       unless other.is_a?(self.class)
37         other = self.class.new(other)
38       end
39       if (ret = @major <=> other.major) == 0
40         return @minor <=> other.minor
41       end
42       return ret
43     end
45     def to_s
46       format("%d.%d", @major, @minor)
47     end
48   end
49 end