class WindowsError::ErrorCode
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](msdn.microsoft.com/en-us/library/cc231196.aspx)
Attributes
@return [String] the description of the error the code represents
@return [String] the name of the error code
@return [Integer] the error code that was given as a return value
Public Class Methods
@param [String] name the 'name' of the error code (i.e STATUS_SUCCESS) @param [Integer] value the return value that represents that error @param [String] description the verbose description of the error @raise [ArgumentError] if any of the parameters are of an invalid type
# 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
Public Instance Methods
Overirdes the equality test for ErrorCodes. Equality is always tested against the value
of the error code.
@param [Object] other_object the object to test equality against @raise [ArgumentError] if the other object is not either another ErrorCode
or a Integer @return [Boolean] whether the equality test passed
# 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 else raise ArgumentError, "Cannot compare a #{self.class} to a #{other_object.class}" end end
# File lib/windows_error/error_code.rb, line 49 def to_s code = sprintf "%08x", self.value "(0x#{code}) #{self.name}: #{self.description}" end