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

Marco Bresciani

Copyright

Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani

License

GNU General Public License version 3

Instance Method Summary collapse

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.



44
45
46
47
48
# File 'lib/wwwjdic/utils/raisers.rb', line 44

def raiser_array(name = 'error.value', value = nil, array = nil)
  unless value.nil?
    raise ArgumentError, I18n.t(name, value: value) unless array.include? value
  end
end

#raiser_downcase(name = 'error.value', value = nil, array = nil) ⇒ Object

Raises an ArgumentError according to parameters, unless the array contains a downcased value.



52
53
54
55
56
# File 'lib/wwwjdic/utils/raisers.rb', line 52

def raiser_downcase(name = 'error.value', value = nil, array = nil)
  unless value.nil?
    raise ArgumentError, I18n.t(name, value: value) unless array.include? value.downcase
  end
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.



60
61
62
63
64
# File 'lib/wwwjdic/utils/raisers.rb', line 60

def raiser_to_i(name = 'error.value', value = nil, array = nil)
  unless value.nil?
    raise ArgumentError, I18n.t(name, value: value) unless array.include? value.to_i
  end
end