Class: WEBrick::HTTPVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/webrick/httpversion.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ HTTPVersion

Returns a new instance of HTTPVersion.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/webrick/httpversion.rb', line 20

def initialize(version)
  case version
  when HTTPVersion
    @major, @minor = version.major, version.minor
  when String
    if /^(\d+)\.(\d+)$/ =~ version
      @major, @minor = $1.to_i, $2.to_i
    end
  end
  if @major.nil? || @minor.nil?
    raise ArgumentError,
      format("cannot convert %s into %s", version.class, self.class)
  end
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



14
15
16
# File 'lib/webrick/httpversion.rb', line 14

def major
  @major
end

#minorObject

Returns the value of attribute minor.



14
15
16
# File 'lib/webrick/httpversion.rb', line 14

def minor
  @minor
end

Class Method Details

.convert(version) ⇒ Object



16
17
18
# File 'lib/webrick/httpversion.rb', line 16

def self.convert(version)
  version.is_a?(self) ? version : new(version)
end

Instance Method Details

#<=>(other) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/webrick/httpversion.rb', line 35

def <=>(other)
  unless other.is_a?(self.class)
    other = self.class.new(other)
  end
  if (ret = @major <=> other.major) == 0
    return @minor <=> other.minor
  end
  return ret
end

#to_sObject



45
46
47
# File 'lib/webrick/httpversion.rb', line 45

def to_s
  format("%d.%d", @major, @minor)
end