~ubuntu-branches/ubuntu/intrepid/ruby1.8/intrepid-updates

« back to all changes in this revision

Viewing changes to lib/webrick/httpversion.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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