Exception: SubCipher::SubCipherError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/sub_cipher/sub_cipher_error.rb

Overview

A customized exception for SubCipher

Constant Summary collapse

ERRORS =

Errors used in SubCipher

{
  :unknown_option => {
    :value => 1,
    :msg => "Unknown option"
  },
  :duplicated_option => {
    :value => 2,
    :msg => "The same options are given."
  },
  :invalid_option_value => {
    :value => 3,
    :msg => "The given option value is invalid."
  },
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, info = {}) ⇒ SubCipherError

The SubCipherError constructor.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sub_cipher/sub_cipher_error.rb', line 29

def initialize(error, info = {})
  @code = error
  @info = info
  if ERRORS.keys.include?(error)
    @value = ERRORS[error][:value]
    @msg = ERRORS[error][:msg]
  elsif error.class.name == 'String'
    @code = :internal
    @value = 90000
    @msg = error
  else
    @code = :internal
    @value = 99999
    @msg = "Internal Error"
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code


22
23
24
# File 'lib/sub_cipher/sub_cipher_error.rb', line 22

def code
  @code
end

#infoObject (readonly)

Returns the value of attribute info


22
23
24
# File 'lib/sub_cipher/sub_cipher_error.rb', line 22

def info
  @info
end

#msgObject (readonly)

Returns the value of attribute msg


22
23
24
# File 'lib/sub_cipher/sub_cipher_error.rb', line 22

def msg
  @msg
end

#valueObject (readonly)

Returns the value of attribute value


22
23
24
# File 'lib/sub_cipher/sub_cipher_error.rb', line 22

def value
  @value
end