lib/aba/validations.rb in aba-0.4.0 vs lib/aba/validations.rb in aba-0.5.0

- old
+ new

@@ -44,10 +44,16 @@ if param self.error_collection << "#{attribute} must be a number" unless value.to_s =~ /\A[+-]?\d+\Z/ else self.error_collection << "#{attribute} must be an unsigned number" unless value.to_s =~ /\A\d+\Z/ end + when :matches_transaction_code + if debit? && value.to_i > 0 + self.error_collection << "#{attribute} is positive but the transaction type is a debit" + elsif credit? && value.to_i < 0 + self.error_collection << "#{attribute} is negative but the transaction type is a credit" + end when :account_number if value.to_s =~ /\A[0\ ]+\Z/ || value.to_s !~ /\A[a-z\d\ ]{1,9}\Z/ self.error_collection << "#{attribute} must be a valid account number" end when :becs @@ -86,10 +92,15 @@ def validates_integer(attribute, signed = true) add_validation_attribute(attribute, :integer, signed) end + def validates_amount(attribute) + add_validation_attribute(attribute, :integer, true) + add_validation_attribute(attribute, :matches_transaction_code) + end + def validates_account_number(attribute) add_validation_attribute(attribute, :account_number) end def validates_becs(attribute) @@ -100,9 +111,13 @@ add_validation_attribute(attribute, :indicator) end def validates_transaction_code(attribute) add_validation_attribute(attribute, :transaction_code) + end + + def validates_return_code(attribute) + add_validation_attribute(attribute, :integer, :return_code) end private def add_validation_attribute(attribute, type, param = true)