Class: Jsapi::Status::Code
Overview
Represents a status code.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.from(value) ⇒ Object
Transforms
valueto an instance of this class. - .status_code(symbol) ⇒ Object
Instance Method Summary collapse
-
#initialize(value) ⇒ Code
constructor
:nodoc:.
-
#match?(status_code) ⇒ Boolean
Returns true if and only if
status_codeis equal to itself.
Methods inherited from Base
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.
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.
108 109 110 |
# File 'lib/jsapi/status/code.rb', line 108 def match?(status_code) status_code == self end |