Class: WEBrick::HTTPVersion
- Inherits:
-
Object
- Object
- WEBrick::HTTPVersion
- Includes:
- Comparable
- Defined in:
- lib/webrick/httpversion.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ HTTPVersion
constructor
A new instance of HTTPVersion.
- #to_s ⇒ Object
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
#major ⇒ Object
Returns the value of attribute major.
14 15 16 |
# File 'lib/webrick/httpversion.rb', line 14 def major @major end |
#minor ⇒ Object
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_s ⇒ Object
45 46 47 |
# File 'lib/webrick/httpversion.rb', line 45 def to_s format("%d.%d", @major, @minor) end |