Class: Jsapi::Status::Code

Inherits:
Base
  • Object
show all
Defined in:
lib/jsapi/status/code.rb

Overview

Represents a status code.

Instance Attribute Summary

Attributes inherited from Base

#priority, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#<=>, #==, #inspect

Constructor Details

#initialize(value) ⇒ Code

:nodoc:



103
104
105
# File 'lib/jsapi/status/code.rb', line 103

def initialize(value) # :nodoc:
  super(value, priority: 1)
end

Class Method Details

.from(value) ⇒ Object

Transforms value to an instance of this class.

Raises an ArgumentError if value could not be transformed.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/jsapi/status/code.rb', line 11

def from(value)
  return value if value.nil? || value.is_a?(Code)

  code = status_code(value.to_sym) if value.respond_to?(:to_sym)
  code ||= value.to_i
  return new(code) if (100..599).cover?(code)

  raise ArgumentError, "invalid status code: #{value.inspect}"
end

.status_code(symbol) ⇒ Object



21
22
23
# File 'lib/jsapi/status/code.rb', line 21

def status_code(symbol)
  symbol_to_code[symbol]
end

Instance Method Details

#match?(status_code) ⇒ Boolean

Returns true if and only if status_code is equal to itself.

Returns:

  • (Boolean)


108
109
110
# File 'lib/jsapi/status/code.rb', line 108

def match?(status_code)
  status_code == self
end