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


48
49
50
51
52
53
54
# File 'lib/plate_map_generation.rb', line 48

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


42
43
44
45
46
# File 'lib/plate_map_generation.rb', line 42

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

.mapsObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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]
    }
  ]
end

Instance Method Details

#save!Object


56
57
58
59
60
61
62
# File 'lib/plate_map_generation.rb', line 56

def save!
  # Abort if we've already generated our shape
  return true if AssetShape.find_by(name: @name)

  @shape = AssetShape.create!(name: @name, horizontal_ratio: @horizontal_ratio, vertical_ratio: @vertical_ratio, description_strategy: @description_strategy)
  @sizes.each { |size| @shape.generate_map(size) }
end