Class: AssetsController::PlateLayout

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#heightObject (readonly)

Returns the value of attribute height


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

def height
  @height
end

#wellsObject (readonly)

Returns the value of attribute wells


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

def wells
  @wells
end

#widthObject (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

Raises:

  • (StandardError)

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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)
  [: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

#sizeObject


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