Class: AssetsController::PlateLayout
- Inherits:
-
Object
- Object
- AssetsController::PlateLayout
- 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
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#wells ⇒ Object
readonly
Returns the value of attribute wells.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #assert_valid_location(location_id) ⇒ Object
- #bad_well_at?(row, column) ⇒ Boolean
- #cell_name_for_well_at(row, column) ⇒ Object
- #empty_well_at?(row, column) ⇒ Boolean
- #good_well_at?(row, column) ⇒ Boolean
-
#initialize(width, height) ⇒ PlateLayout
constructor
A new instance of PlateLayout.
- #location_for_well_at(row, column) ⇒ Object
- #set_details_for_well_at(location_id, details) ⇒ Object
- #size ⇒ Object
- #well_at(row, column) ⇒ Object
Constructor Details
#initialize(width, height) ⇒ PlateLayout
Returns a new instance of PlateLayout.
11 12 13 14 |
# File 'app/controllers/assets/plate_layout.rb', line 11 def initialize(width, height) @width, @height = width, height @wells = (1..@width * @height).map { |_| DEFAULT_WELL.dup } end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height
9 10 11 |
# File 'app/controllers/assets/plate_layout.rb', line 9 def height @height end |
#wells ⇒ Object (readonly)
Returns the value of attribute wells
9 10 11 |
# File 'app/controllers/assets/plate_layout.rb', line 9 def wells @wells end |
#width ⇒ Object (readonly)
Returns the value of attribute width
9 10 11 |
# File 'app/controllers/assets/plate_layout.rb', line 9 def width @width end |
Instance Method Details
#assert_valid_location(location_id) ⇒ Object
53 54 55 |
# File 'app/controllers/assets/plate_layout.rb', line 53 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
48 49 50 51 |
# File 'app/controllers/assets/plate_layout.rb', line 48 def bad_well_at?(row, column) well = well_at(row, column) not well[:error].nil? end |
#cell_name_for_well_at(row, column) ⇒ Object
25 26 27 |
# File 'app/controllers/assets/plate_layout.rb', line 25 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
39 40 41 |
# File 'app/controllers/assets/plate_layout.rb', line 39 def empty_well_at?(row, column) DEFAULT_WELL == well_at(row, column) end |
#good_well_at?(row, column) ⇒ Boolean
43 44 45 46 |
# File 'app/controllers/assets/plate_layout.rb', line 43 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
29 30 31 |
# File 'app/controllers/assets/plate_layout.rb', line 29 def location_for_well_at(row, column) ((row * @width) + column) + 1 end |
#set_details_for_well_at(location_id, details) ⇒ Object
16 17 18 19 |
# File 'app/controllers/assets/plate_layout.rb', line 16 def set_details_for_well_at(location_id, details) assert_valid_location(location_id) @wells[location_id - 1] = details end |
#size ⇒ Object
21 22 23 |
# File 'app/controllers/assets/plate_layout.rb', line 21 def size @width * @height end |
#well_at(row, column) ⇒ Object
33 34 35 36 37 |
# File 'app/controllers/assets/plate_layout.rb', line 33 def well_at(row, column) location_id = location_for_well_at(row, column) assert_valid_location(location_id) @wells[location_id - 1] end |