lib/alex_codebreaker/modules/validators/validators.rb in alex_codebreaker-0.1.4 vs lib/alex_codebreaker/modules/validators/validators.rb in alex_codebreaker-0.1.5
- old
+ new
@@ -1,19 +1,17 @@
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)
+ def argument_fixed_length_check(arg, fixed_length)
+ arg.to_s.length == fixed_length
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
+ def argument_max_length_check(arg, max)
+ arg.length <= max
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
+ def argument_min_length_check(arg, 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?
+ def digits_check(arg, min_digit: 1, max_digit: 6)
+ arg.to_s.split('').map { |value| value unless value.to_i.between?(min_digit, max_digit) }.compact.empty?
end
end