Class: Restspec::Values::StatusCode

Inherits:
Object
  • Object
show all
Defined in:
lib/restspec/values/status_code.rb

Overview

A value object that transforms a http status code (201) or a symbol with the status code message (:created) to a simple number (201).

Instance Method Summary collapse

Constructor Details

#initialize(number_or_symbol) ⇒ StatusCode

Returns a new instance of StatusCode.



7
8
9
# File 'lib/restspec/values/status_code.rb', line 7

def initialize(number_or_symbol)
  self.number_or_symbol = number_or_symbol
end

Instance Method Details

#valueFixnum

Returns the status code.

Examples:

StatusCode.new(201).value # 201
StatusCode.new(:created).value # 201

Returns:

  • (Fixnum)

    the status code



15
16
17
18
19
20
21
# File 'lib/restspec/values/status_code.rb', line 15

def value
  if number_or_symbol.is_a?(Symbol)
    Rack::Utils::SYMBOL_TO_STATUS_CODE.fetch(number_or_symbol)
  else
    number_or_symbol
  end
end