Class: IscCodeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/isc_code_validator.rb

Instance Method Summary collapse

Instance Method Details

#attribute_message(isc_lookup, object) ⇒ Object



32
33
34
35
36
37
38
39
# File 'app/validators/isc_code_validator.rb', line 32

def attribute_message(isc_lookup, object)
  if isc_lookup.isc_lookup_value == IscCode.inactivation_code
    message = "x0100 => #{object.x0100} "
  else
    message = "a0200 => #{object.a0200}, a0310a => #{object.a0310a}, a0310b => #{object.a0310b}, a0310c => #{object.a0310c}, a0310d => #{object.a0310d}, a0310f => #{object.a0310f}."
  end
  message
end

#build_error_message(object, isc_lookup) ⇒ Object

—————————————————————–# Removing the custom message below for performance reasons # —————————————————————–#



14
15
16
17
18
19
20
# File 'app/validators/isc_code_validator.rb', line 14

def build_error_message(object, isc_lookup)
  message = "The ISC value in this file (#{isc_lookup.isc_provided_value}), "
  message += cms_table_message(isc_lookup)
  message += "Please ensure these values are correct: "
  message += attribute_message(isc_lookup, object)
  message
end

#cms_table_message(isc_lookup) ⇒ Object



23
24
25
26
27
28
29
30
# File 'app/validators/isc_code_validator.rb', line 23

def cms_table_message(isc_lookup)
  if isc_lookup.isc_lookup_value.nil?
    message = "does not match any value provided in the CMS lookup table. "
  else
    message = "does not match the value provided in the CMS lookup table (#{isc_lookup.isc_lookup_value}). "
  end
  message
end

#validate_each(object, attribute, value) ⇒ Object



4
5
6
7
# File 'app/validators/isc_code_validator.rb', line 4

def validate_each(object, attribute, value)
  isc_lookup = Services::IscCodeLookup.new(object)
  object.errors[attribute] << "The ISC Code provided: #{isc_lookup.isc_provided_value} is incorrect for this assessment." unless isc_lookup.valid_isc_value?
end