Module: MbraveTagsCreator::StaticMethods

Included in:
MbraveTagsCreator
Defined in:
lib/mbrave_tags_creator.rb

Instance Method Summary collapse

Instance Method Details

#create_tag_plates(tag_layout_templates, user) ⇒ Object

rubocop:disable Metrics/AbcSize



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/mbrave_tags_creator.rb', line 152

def create_tag_plates(tag_layout_templates, user) # rubocop:todo Metrics/MethodLength
  ActiveRecord::Base.transaction do
    lot_type = LotType.find_by!(name: 'Pre Stamped Tags - 384')
    tag_layout_templates.each_with_index do |tag_layout_template, _index|
      lot =
        lot_type.lots.create!(
          lot_number: "PSD_#{Time.current.to_f}",
          template: tag_layout_template,
          user: user,
          received_at: Time.current
        )
      text_code = text_code_for_tag_layout(tag_layout_template)
      plate_barcode = PlateBarcode.create_barcode_with_text(text_code) # barcode object

      qcc = QcableCreator.create!(lot: lot, user: user, supplied_barcode: plate_barcode)
      qcc.qcables.each_with_index do |qcable, _index|
        qcable.update!(state: 'available')
        log_line { "#{tag_layout_template.name}:" }
        log_line { " - #{plate_barcode.barcode}" } # barcode string
      end
    end
  end
end

#process_create_tag_groups(forward_filename, reverse_filename, version) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/mbrave_tags_creator.rb', line 189

def process_create_tag_groups(forward_filename, reverse_filename, version)
  ActiveRecord::Base.transaction do
    mbrave_tags_creator =
      MbraveTagsCreator.new(
        forward_filename: forward_filename,
        reverse_filename: reverse_filename,
        tag_identifier: MbraveTagsCreator::TAG_IDENTIFIER,
        version: version,
        yaml_filename: MbraveTagsCreator::YAML_FILENAME
      )

    mbrave_tags_creator.create_1_tag_group_forward
    mbrave_tags_creator.create_24_tag_groups_reverse
    mbrave_tags_creator.create_tag_layout_templates
    mbrave_tags_creator.write_yaml(MbraveTagsCreator::YAML_FILENAME)
  end
end

#process_create_tag_plates(login, version) ⇒ Object

rubocop:enable Metrics/AbcSize



178
179
180
181
182
183
184
185
186
187
# File 'lib/mbrave_tags_creator.rb', line 178

def process_create_tag_plates(, version)
  user = User.find_by!(login:)

  tag_layout_templates =
    TagLayoutTemplate.select do |template|
      template.name.match(Regexp.new("^Bioscan_384_template_(\\d+)_#{version}$"))
    end

  create_tag_plates(tag_layout_templates, user)
end

#text_code_for_tag_layout(tag_layout_template) ⇒ Object



146
147
148
149
# File 'lib/mbrave_tags_creator.rb', line 146

def text_code_for_tag_layout(tag_layout_template)
  mreg = tag_layout_template.name.match(Regexp.new('^Bioscan_384_template_(\\d+)_'))
  "T#{mreg[1]}"
end