Class: PlateMapGeneration

Inherits:
Object
  • Object
show all
Defined in:
lib/plate_map_generation.rb

Overview

This class sites around for idempotent generation of plate shapes and maps until the behaviour can be re-factored to remove dependency on the database. This assumes the shapes will not change

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, horizontal_ratio:, vertical_ratio:, sizes:, description_strategy: 'coordinate') ⇒ PlateMapGeneration

Returns a new instance of PlateMapGeneration.



36
37
38
39
40
41
42
# File 'lib/plate_map_generation.rb', line 36

def initialize(name:, horizontal_ratio:, vertical_ratio:, sizes:, description_strategy: 'coordinate')
  @name = name
  @horizontal_ratio = horizontal_ratio
  @vertical_ratio = vertical_ratio
  @sizes = sizes
  @description_strategy = "Map::#{description_strategy.camelcase}"
end

Class Method Details

.generate!Object

Idempotent method of generating required asset shapes and maps



32
33
34
# File 'lib/plate_map_generation.rb', line 32

def self.generate!
  ActiveRecord::Base.transaction { maps.each { |config| new(**config).save! } }
end

.mapsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/plate_map_generation.rb', line 8

def self.maps
  [
    {
      name: 'Standard',
      horizontal_ratio: 3,
      vertical_ratio: 2,
      description_strategy: 'Coordinate',
      sizes: [96, 384]
    },
    { name: 'Fluidigm96', horizontal_ratio: 3, vertical_ratio: 8, description_strategy: 'Sequential', sizes: [96] },
    { name: 'Fluidigm192', horizontal_ratio: 3, vertical_ratio: 4, description_strategy: 'Sequential', sizes: [192] },
    {
      name: 'StripTubeColumn',
      horizontal_ratio: 1,
      vertical_ratio: 8,
      description_strategy: 'Sequential',
      sizes: [8]
    },
    { name: 'Shape4x1', horizontal_ratio: 4, vertical_ratio: 1, description_strategy: 'Coordinate', sizes: [16] },
    { name: 'Shape8x1', horizontal_ratio: 8, vertical_ratio: 1, description_strategy: 'Coordinate', sizes: [8] }
  ]
end

Instance Method Details

#save!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/plate_map_generation.rb', line 44

def save!
  @shape =
    AssetShape.create_with(
      horizontal_ratio: @horizontal_ratio,
      vertical_ratio: @vertical_ratio,
      description_strategy: @description_strategy
    ).find_or_create_by!(name: @name)

  @sizes.each do |size|
    next if Map.find_by(asset_size: size, asset_shape_id: @shape.id).present?

    @shape.generate_map(size)
  end
end