Class: Brut::FrontEnd::HttpStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/front_end/http_status.rb

Overview

Wrapper around an HTTP status, that can also normalize strings that contain status codes.

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ HttpStatus

Create an http status

Parameters:

  • number (Integer|String)

    the status code. to_i is used to coerce this into a number.

Raises:

  • (ArgumentError)

    if the value is lower than 100 or greater than 599. Note that the spec allows any value in that range to be considered a valid HTTP status code



9
10
11
12
13
14
15
# File 'lib/brut/front_end/http_status.rb', line 9

def initialize(number)
  number = number.to_i
  if ((number < 100) || (number > 599))
    raise ArgumentError,"'#{number}' is not a known HTTP status code"
  end
  @number = number
end

Instance Method Details

#==(other) ⇒ true|false

Returns true if the other object has the same class as this and has the same numeric representation.

Returns:

  • (true|false)

    true if the other object has the same class as this and has the same numeric representation



23
24
25
# File 'lib/brut/front_end/http_status.rb', line 23

def ==(other)
  self.class == other.class && self.to_i == other.to_i
end

#to_iNumber

Returns the value as a number.

Returns:

  • (Number)

    the value as a number



18
19
# File 'lib/brut/front_end/http_status.rb', line 18

def to_i = @number
# @return [String] the value as a string

#to_sString

Returns the value as a string.

Returns:

  • (String)

    the value as a string



20
# File 'lib/brut/front_end/http_status.rb', line 20

def to_s = to_i.to_s