Class: Services::IscCodeLookup

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/services/isc_code_lookup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assessment) ⇒ IscCodeLookup

——————————————————————# Raises an ArgumentError if itm_sbst_cd (provided isc value) # does not exist. since this class depends on the comparison # between the calculated isc and the provided isc values. # ——————————————————————#

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'app/models/services/isc_code_lookup.rb', line 25

def initialize(assessment)
  raise(ArgumentError, "The attribute 'itm_sbst_cd' does not exist") unless assessment.respond_to?("itm_sbst_cd")
  @isc_provided_value = assessment.itm_sbst_cd
  @isc_lookup_value = find_isc_value(assessment)
end

Instance Attribute Details

#isc_lookup_valueObject (readonly)

Returns the value of attribute isc_lookup_value.



18
19
20
# File 'app/models/services/isc_code_lookup.rb', line 18

def isc_lookup_value
  @isc_lookup_value
end

#isc_provided_valueObject (readonly)

Returns the value of attribute isc_provided_value.



18
19
20
# File 'app/models/services/isc_code_lookup.rb', line 18

def isc_provided_value
  @isc_provided_value
end

Instance Method Details

#find_isc_value(assessment) ⇒ Object

——————————————————————#

Finds and returns the actual isc code (eg: "NC")                #
Returns nil if:                                                 #
  1) any of the attributes required for isc calculation are nil #
  2) isc code is not found due to an invalid combination of     #
     required attributes                                        #

——————————————————————#



38
39
40
41
42
43
44
45
# File 'app/models/services/isc_code_lookup.rb', line 38

def find_isc_value(assessment)
  return Services::IscCode.inactivation_code if inactivation_isc?(assessment)

  if all_lookup_attributes_exist?(assessment)
    isc_lookup = self.class.isc_lookup(assessment).first
    isc_lookup.isc_code.code if isc_lookup
  end
end

#valid_isc_value?Boolean

—————————————————————-#

Returns whether the calculated isc code is the same as        #
the provided isc code                                         #

—————————————————————-#

Returns:

  • (Boolean)


51
52
53
54
# File 'app/models/services/isc_code_lookup.rb', line 51

def valid_isc_value?()
  return if @isc_provided_value.nil?
  @isc_lookup_value == @isc_provided_value
end