Class: AssetsController::PlateLayout

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/assets/plate_layout.rb

Overview

rubocop:todo Style/Documentation

Constant Summary collapse

DEFAULT_WELL =
{ request: nil, asset: nil, error: nil }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ PlateLayout

Returns a new instance of PlateLayout.


12
13
14
15
# File 'app/controllers/assets/plate_layout.rb', line 12

def initialize(width, height)
  @width, @height = width, height
  @wells = (1..@width * @height).map { |_| DEFAULT_WELL.dup }
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.


10
11
12
# File 'app/controllers/assets/plate_layout.rb', line 10

def height
  @height
end

#wellsObject (readonly)

Returns the value of attribute wells.


10
11
12
# File 'app/controllers/assets/plate_layout.rb', line 10

def wells
  @wells
end

#widthObject (readonly)

Returns the value of attribute width.


10
11
12
# File 'app/controllers/assets/plate_layout.rb', line 10

def width
  @width
end

Instance Method Details

#assert_valid_location(location_id) ⇒ Object

Raises:

  • (StandardError)

54
55
56
# File 'app/controllers/assets/plate_layout.rb', line 54

def assert_valid_location(location_id)
  raise StandardError, 'Location out of bounds' unless (1..size).cover?(location_id)
end

#bad_well_at?(row, column) ⇒ Boolean

Returns:

  • (Boolean)

49
50
51
52
# File 'app/controllers/assets/plate_layout.rb', line 49

def bad_well_at?(row, column)
  well = well_at(row, column)
  not well[:error].nil?
end

#cell_name_for_well_at(row, column) ⇒ Object


26
27
28
# File 'app/controllers/assets/plate_layout.rb', line 26

def cell_name_for_well_at(row, column)
  Map.find_by(location_id: ((row * width) + column + 1), asset_size: size).description
end

#empty_well_at?(row, column) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
# File 'app/controllers/assets/plate_layout.rb', line 40

def empty_well_at?(row, column)
  DEFAULT_WELL == well_at(row, column)
end

#good_well_at?(row, column) ⇒ Boolean

Returns:

  • (Boolean)

44
45
46
47
# File 'app/controllers/assets/plate_layout.rb', line 44

def good_well_at?(row, column)
  well = well_at(row, column)
  %i[request asset].all? { |field| not well[field].nil? }
end

#location_for_well_at(row, column) ⇒ Object


30
31
32
# File 'app/controllers/assets/plate_layout.rb', line 30

def location_for_well_at(row, column)
  ((row * @width) + column) + 1
end

#set_details_for_well_at(location_id, details) ⇒ Object


17
18
19
20
# File 'app/controllers/assets/plate_layout.rb', line 17

def set_details_for_well_at(location_id, details)
  assert_valid_location(location_id)
  @wells[location_id - 1] = details
end

#sizeObject


22
23
24
# File 'app/controllers/assets/plate_layout.rb', line 22

def size
  @width * @height
end

#well_at(row, column) ⇒ Object


34
35
36
37
38
# File 'app/controllers/assets/plate_layout.rb', line 34

def well_at(row, column)
  location_id = location_for_well_at(row, column)
  assert_valid_location(location_id)
  @wells[location_id - 1]
end