Class: WindowsError::ErrorCode
- Inherits:
-
Object
- Object
- WindowsError::ErrorCode
- Defined in:
- lib/windows_error/error_code.rb
Overview
This is the core class that represents a Windows Error Code. It maps the error code value to the description of the error according to Microsoft documentation found at Windows Error Codes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The description of the error the code represents.
-
#name ⇒ String
readonly
The name of the error code.
-
#value ⇒ Integer
readonly
The error code that was given as a return value.
Instance Method Summary collapse
-
#==(other_object) ⇒ Boolean
(also: #===)
Overrides the equality test for ErrorCodes.
-
#initialize(name, value, description) ⇒ ErrorCode
constructor
A new instance of ErrorCode.
- #to_s ⇒ Object
Constructor Details
#initialize(name, value, description) ⇒ ErrorCode
Returns a new instance of ErrorCode.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/windows_error/error_code.rb', line 18 def initialize(name, value, description) raise ArgumentError, 'Invalid Error Name!' unless name.kind_of? String and !(name.empty?) raise ArgumentError, 'Invalid Error Code Value!' unless value.kind_of? Integer raise ArgumentError, 'Invalid Error Description!' unless description.kind_of? String and !(description.empty?) @name = name @value = value @description = description @name.freeze @value.freeze @description.freeze self.freeze end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns the description of the error the code represents.
8 9 10 |
# File 'lib/windows_error/error_code.rb', line 8 def description @description end |
#name ⇒ String (readonly)
Returns the name of the error code.
10 11 12 |
# File 'lib/windows_error/error_code.rb', line 10 def name @name end |
#value ⇒ Integer (readonly)
Returns the error code that was given as a return value.
12 13 14 |
# File 'lib/windows_error/error_code.rb', line 12 def value @value end |
Instance Method Details
#==(other_object) ⇒ Boolean Also known as: ===
Overrides the equality test for ErrorCodes. Equality is always tested against the #value of the error code.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/windows_error/error_code.rb', line 37 def ==(other_object) if other_object.kind_of? self.class self.value == other_object.value elsif other_object.kind_of? Integer self.value == other_object elsif other_object.nil? false else raise ArgumentError, "Cannot compare a #{self.class} to a #{other_object.class}" end end |
#to_s ⇒ Object
51 52 53 54 |
# File 'lib/windows_error/error_code.rb', line 51 def to_s code = sprintf "%08x", self.value "(0x#{code}) #{self.name}: #{self.description}" end |