Module: Nacha::Record::Validations::FieldValidations::ClassMethods

Defined in:
lib/nacha/record/validations/field_validations.rb

Instance Method Summary collapse

Instance Method Details

#check_field_error(field, _message = nil, condition = nil) ⇒ Object



13
14
15
16
# File 'lib/nacha/record/validations/field_validations.rb', line 13

def check_field_error(field, _message = nil, condition = nil)
  (block_given? ? yield : condition) ||
    (field.add_error("'#{field.name}' '#{field}' is invalid") && false)
end

#valid_filler(field) ⇒ Object



50
51
52
# File 'lib/nacha/record/validations/field_validations.rb', line 50

def valid_filler(field)
  check_field_error(field) { field.to_s == ('9' * 93) }
end

#valid_receiving_dfi_identification(field) ⇒ Object



46
47
48
# File 'lib/nacha/record/validations/field_validations.rb', line 46

def valid_receiving_dfi_identification(field)
  check_field_error(field) { field.valid? }
end

#valid_service_class_code(field) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/nacha/record/validations/field_validations.rb', line 18

def valid_service_class_code(field)
  check_field_error(
    field,
    "'#{field.name}' '#{field}' should be one of #{SERVICE_CLASS_CODES.join(', ')}"
  ) do
    SERVICE_CLASS_CODES.include? field.to_s
  end
end

#valid_standard_entry_class_code(field) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/nacha/record/validations/field_validations.rb', line 27

def valid_standard_entry_class_code(field)
  check_field_error(
    field,
    "'#{field.name}' '#{field}' should be one of " \
      "#{STANDARD_ENTRY_CLASS_CODES.join(', ')}"
  ) do
    STANDARD_ENTRY_CLASS_CODES.include? field.data
  end
end

#valid_transaction_code(field) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/nacha/record/validations/field_validations.rb', line 37

def valid_transaction_code(field)
  check_field_error(
    field,
    "'#{field.name}' '#{field}' should be one of #{TRANSACTION_CODES.join(', ')}"
  ) do
    TRANSACTION_CODES.include? field.to_s
  end
end