Module: WWWJDic::Utils::Raisers
- Included in:
- Parsers::Dict, Parsers::Display, Parsers::Key, Parsers::Server
- Defined in:
- lib/wwwjdic/utils/raisers.rb
Overview
This module contains some utility method to raise errors according to (possibly) common conditions.
- Author
- Copyright
-
© 2014-2021 Marco Bresciani
- License
-
GNU General Public License version 3
Instance Method Summary collapse
-
#raiser_array(name = 'error.value', value = nil, array = nil) ⇒ Object
Raises an
ArgumentErroraccording to parameters, unless thearraycontains the exactvalue. -
#raiser_downcase(name = 'error.value', value = nil, array = nil) ⇒ Object
Raises an
ArgumentErroraccording to parameters, unless thearraycontains a downcasedvalue. -
#raiser_to_i(name = 'error.value', value = nil, array = nil) ⇒ Object
Raises an
ArgumentErroraccording to parameters, unless thearraycontains the number of thevalue.
Instance Method Details
#raiser_array(name = 'error.value', value = nil, array = nil) ⇒ Object
Raises an ArgumentError according to parameters, unless the array contains the exact value.
47 48 49 |
# File 'lib/wwwjdic/utils/raisers.rb', line 47 def raiser_array(name = 'error.value', value = nil, array = nil) raise ArgumentError, I18n.t(name, value: value) if !value.nil? && !(array.include? value) end |
#raiser_downcase(name = 'error.value', value = nil, array = nil) ⇒ Object
Raises an ArgumentError according to parameters, unless the array contains a downcased value.
53 54 55 |
# File 'lib/wwwjdic/utils/raisers.rb', line 53 def raiser_downcase(name = 'error.value', value = nil, array = nil) raise ArgumentError, I18n.t(name, value: value) if !value.nil? && !(array.include? value.downcase) end |
#raiser_to_i(name = 'error.value', value = nil, array = nil) ⇒ Object
Raises an ArgumentError according to parameters, unless the array contains the number of the value.
59 60 61 |
# File 'lib/wwwjdic/utils/raisers.rb', line 59 def raiser_to_i(name = 'error.value', value = nil, array = nil) raise ArgumentError, I18n.t(name, value: value) if !value.nil? && !(array.include? value.to_i) end |