class Status

A small HTTP status wrapper that verifies the status code within a given range.

Definitions

def initialize(code, valid_range = 100...600)

Initialize a validated HTTP status.

Signature

parameter code Integer | Symbol

The numeric status or a key from STATUS_CODES = {...}.

parameter valid_range Range

The accepted numeric status range.

raises ArgumentError

If the resolved status is outside valid_range.

Implementation

def initialize(code, valid_range = 100...600)
	if code.is_a? Symbol
		code = STATUS_CODES[code]
	end
	
	unless valid_range.include? code
		raise ArgumentError.new("Status must be in range #{valid_range}, was given #{code}!")
	end
	
	@code = code
end

def to_i

Convert this value to an integer.

Signature

returns Integer

The numeric status code.

Implementation

def to_i
	@code
end

def to_s

Convert this object to a string.

Signature

returns String

The resulting string.

Implementation

def to_s
	return Protocol::HTTP::Status.description(@code) || @code.to_s
end