module Validators def argument_instance_check(arg, checking_class) raise WrongClass, (I18n.t(:value_instance_of) + checking_class.to_s) unless arg.instance_of?(checking_class) end def argument_fixed_length_check(arg, fix_length) message = I18n.t(:invalid_argument_length) + fix_length.to_s + I18n.t(:given) + arg.to_s.length.to_s raise InvalidLength, message unless arg.to_s.length == fix_length end def argument_length_check(arg, max: nil, min: nil) raise InvalidLength, (I18n.t(:argument_length_long) + max.to_s) if max && arg.length > max raise InvalidLength, (I18n.t(:argument_length_short) + min.to_s) if min && arg.length < min end def digits_check(arg) raise InvalidDigit unless arg.to_s.split('').map { |value| value unless value.to_i.between?(1, 6) }.compact.empty? end end