Class: Asset::Finder
- Inherits:
-
Object
- Object
- Asset::Finder
- Defined in:
- app/models/asset/finder.rb
Overview
Taked barcodes and locations and returns matching assets eg DN123456P:A1,A2,A3 (Wells A1,A2,A3) DN123456P:1,2,3 (Columns 1,2,3) DN123456P:A,B (Rows A,B) DN123456P (Entire Plate) Imported from SubmissionCreator with minor adaptations to support tubes. Could do with refactoring and performance improvements
Constant Summary collapse
- InvalidInputException =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#barcodes_wells ⇒ Object
readonly
Returns the value of attribute barcodes_wells.
-
#processed_barcodes ⇒ Object
readonly
Returns the value of attribute processed_barcodes.
Instance Method Summary collapse
-
#barcodes ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
-
#find_wells_in_array(plate, well_array) ⇒ Object
rubocop:todo Metrics/MethodLength, Metrics/AbcSize.
-
#initialize(barcode_locations) ⇒ Finder
constructor
A new instance of Finder.
- #resolve ⇒ Object
Constructor Details
#initialize(barcode_locations) ⇒ Finder
Returns a new instance of Finder.
15 16 17 |
# File 'app/models/asset/finder.rb', line 15 def initialize() @barcodes_wells = .map { |bc_well| bc_well.split(':') } end |
Instance Attribute Details
#barcodes_wells ⇒ Object (readonly)
Returns the value of attribute barcodes_wells.
13 14 15 |
# File 'app/models/asset/finder.rb', line 13 def @barcodes_wells end |
#processed_barcodes ⇒ Object (readonly)
Returns the value of attribute processed_barcodes.
13 14 15 |
# File 'app/models/asset/finder.rb', line 13 def @processed_barcodes end |
Instance Method Details
#barcodes ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
58 59 60 |
# File 'app/models/asset/finder.rb', line 58 def .map(&:first).uniq end |
#find_wells_in_array(plate, well_array) ⇒ Object
rubocop:todo Metrics/MethodLength, Metrics/AbcSize
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/asset/finder.rb', line 31 def find_wells_in_array(plate, well_array) # rubocop:todo Metrics/CyclomaticComplexity return plate.wells.in_column_major_order.with_aliquots.distinct if well_array.empty? well_array.flat_map do |map_description| case map_description when /^[a-z,A-Z][0-9]+$/ # A well well = plate.find_well_by_name(map_description) if well.nil? || well.aliquots.empty? raise InvalidInputException, "Well #{map_description} on #{plate.} does not exist or is empty." end well when /^[a-z,A-Z]$/ # A row plate.wells.with_aliquots.in_plate_row(map_description, plate.size).distinct when /^[0-9]+$/ # A column plate.wells.with_aliquots.in_plate_column(map_description, plate.size).distinct else raise InvalidInputException, "#{map_description} is not a valid well location" end end end |
#resolve ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/asset/finder.rb', line 19 def resolve .flat_map do |, well_locations| labware = Labware.() raise InvalidInputException, "No labware found for barcode #{}." if labware.nil? well_array = (well_locations || '').split(',').map(&:strip).compact_blank labware.respond_to?(:wells) ? find_wells_in_array(labware, well_array) : labware end end |