Class: NcsNavigator::Warehouse::Transformers::EnumTransformer::PsuIdChecker
- Inherits:
-
Object
- Object
- NcsNavigator::Warehouse::Transformers::EnumTransformer::PsuIdChecker
- Includes:
- RecordIdent
- Defined in:
- lib/ncs_navigator/warehouse/transformers/enum_transformer.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#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.
-
#initialize(log, psus) ⇒ PsuIdChecker
constructor
A new instance of PsuIdChecker.
- #verify_or_report_errors(record, status) ⇒ Object
Methods included from RecordIdent
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
#log ⇒ Object (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
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 |