Class: NcsNavigator::Warehouse::Transformers::EnumTransformer::PsuIdChecker

Inherits:
Object
  • Object
show all
Includes:
RecordIdent
Defined in:
lib/ncs_navigator/warehouse/transformers/enum_transformer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RecordIdent

#record_ident

Constructor Details

#initialize(log, psus) ⇒ PsuIdChecker

Returns a new instance of PsuIdChecker.



191
192
193
194
# File 'lib/ncs_navigator/warehouse/transformers/enum_transformer.rb', line 191

def initialize(log, psus)
  @log = log
  @psus = psus
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



189
190
191
# File 'lib/ncs_navigator/warehouse/transformers/enum_transformer.rb', line 189

def log
  @log
end

Instance Method Details

#has_valid_psu?(record) ⇒ Boolean

Has valid PSU is true if:

  • The record has no PSU reference, or
  • The record's PSU ID is one of those configured for the study center

Returns:

  • (Boolean)


201
202
203
204
205
206
207
# File 'lib/ncs_navigator/warehouse/transformers/enum_transformer.rb', line 201

def has_valid_psu?(record)
  if record.respond_to?(:psu_id)
    @psus.collect(&:id).include?(record.psu_id)
  else
    true
  end
end

#verify_or_report_errors(record, status) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/ncs_navigator/warehouse/transformers/enum_transformer.rb', line 209

def verify_or_report_errors(record, status)
  if has_valid_psu?(record)
    true
  else
    msg = "Invalid PSU ID. The list of valid PSU IDs for this Study Center is #{@psus.collect(&:id).inspect}."
    log.error "#{record_ident record}: #{msg}"
    status.unsuccessful_record(record, msg,
      :attribute_name => 'psu_id',
      :attribute_value => record.psu_id.inspect)
    false
  end
end