Class: UatActions::GenerateFluidxBarcodes

Inherits:
UatActions
  • Object
show all
Defined in:
app/uat_actions/uat_actions/generate_fluidx_barcodes.rb

Overview

UAT action to generate randomised FluidX barcodes in the following format: <prefix><random><suffix>: Ten characters in total <prefix>: two uppercase letters <random>: six random digits; may be truncated from the end to fit the length <suffix>: <zero><index> <zero>: one digit that separates random part and index, i.e. ‘0’ <index>: sequential tail, 1 to 3 digits, e.g., ‘9’, ‘99’, and ‘999’

Sequential tail in barcodes may be higher and may have gaps because of handling duplicates. Random part may be truncated from right to fit the length of the barcode.

Constant Summary

Constants inherited from UatActions

CATEGORY_LIST

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UatActions

all, category, find, form_field, form_fields, #form_fields, grouped_and_sorted_uat_actions, id, inherited, permitted, #report, #save, to_partial_path, uat_actions

Class Method Details

.defaultUatActions::GenerateFluidxBarcodes

Returns a default copy of the UatAction which will be used to fill in the form.

Returns:



94
95
96
# File 'app/uat_actions/uat_actions/generate_fluidx_barcodes.rb', line 94

def self.default
  new(barcode_count: '1', barcode_prefix: 'TS', barcode_index: '1')
end

Instance Method Details

#performBoolean

This method is called from the save method after validations have passed. If the return value is true, the report hash populated by the action is used for rendering the response. If the return value is false, the errors collection is used.

Returns:

  • (Boolean)

    true if the action was successful; false otherwise



79
80
81
82
83
84
85
86
87
88
89
# File 'app/uat_actions/uat_actions/generate_fluidx_barcodes.rb', line 79

def perform
  random = generate_random
  barcodes = generate_barcodes(barcode_count.to_i, barcode_prefix, random, barcode_index.to_i)
  if barcodes.size == barcode_count.to_i
    report['barcodes'] = barcodes
    true
  else
    errors.add(:base, 'Failed to generate unique barcodes')
    false
  end
end