Class: WEBrick::HTTPVersion

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb

Overview

Represents an HTTP protocol version

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ HTTPVersion

Creates a new HTTPVersion from version.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb', line 39

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

The major protocol version number



22
23
24
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb', line 22

def major
  @major
end

#minorObject

The minor protocol version number



27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb', line 27

def minor
  @minor
end

Class Method Details

.convert(version) ⇒ Object

Converts version into an HTTPVersion



32
33
34
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb', line 32

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

Instance Method Details

#<=>(other) ⇒ Object

Compares this version with other according to the HTTP specification rules.



58
59
60
61
62
63
64
65
66
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb', line 58

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

The HTTP version as show in the HTTP request and response. For example, “1.1”



72
73
74
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/webrick-1.7.0/lib/webrick/httpversion.rb', line 72

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