Line | |
---|
1 | #
|
---|
2 | # HTTPVersion.rb -- presentation of HTTP version
|
---|
3 | #
|
---|
4 | # Author: IPR -- Internet Programming with Ruby -- writers
|
---|
5 | # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
|
---|
6 | # reserved.
|
---|
7 | #
|
---|
8 | # $IPR: httpversion.rb,v 1.5 2002/09/21 12:23:37 gotoyuzo Exp $
|
---|
9 |
|
---|
10 | module WEBrick
|
---|
11 | class HTTPVersion
|
---|
12 | include Comparable
|
---|
13 |
|
---|
14 | attr_accessor :major, :minor
|
---|
15 |
|
---|
16 | def self.convert(version)
|
---|
17 | version.is_a?(self) ? version : new(version)
|
---|
18 | end
|
---|
19 |
|
---|
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
|
---|
34 |
|
---|
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
|
---|
44 |
|
---|
45 | def to_s
|
---|
46 | format("%d.%d", @major, @minor)
|
---|
47 | end
|
---|
48 | end
|
---|
49 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.