Module: LabwareHelper

Defined in:
app/helpers/labware_helper.rb

Overview

rubocop:todo Style/Documentation

Constant Summary collapse

STANDARD_COLOURS =
(1..384).map { |i| "colour-#{i}" }
FAILED_STATES =
%w[failed cancelled].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cycling_colours(name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/labware_helper.rb', line 15

def self.cycling_colours(name)
  define_method(:"#{name}_colour") do |*args|
    return 'failed' if FAILED_STATES.include?(args.first) # First argument is always the well

    @colours ||= Hash.new { |h, k| h[k] = STANDARD_COLOURS.dup }
    @rotating ||=
      Hash.new do |h, k|
        h[k] = @colours[name].rotate!.last # rubocop:todo Rails/HelperInstanceVariable
      end
    @rotating[yield(*args)] # rubocop:todo Rails/HelperInstanceVariable
  end
end

Instance Method Details

#colours_by_locationObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/labware_helper.rb', line 39

def colours_by_location
  return @location_colours if @location_colours.present? # rubocop:todo Rails/HelperInstanceVariable

  @location_colours = {} # rubocop:todo Rails/HelperInstanceVariable

  ('A'..'H').each_with_index do |row, row_index|
    (1..12).each_with_index do |col, col_index|
      @location_colours[row + col.to_s] = # rubocop:todo Rails/HelperInstanceVariable
        "colour-#{(col_index * 8) + row_index + 1}"
    end
  end

  @location_colours # rubocop:todo Rails/HelperInstanceVariable
end

#failable?(container) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/helpers/labware_helper.rb', line 31

def failable?(container)
  container.passed? && container.control_info != 'negative'
end

#labware_by_state(labwares) ⇒ Object



54
55
56
# File 'app/helpers/labware_helper.rb', line 54

def labware_by_state(labwares)
  labwares.group_by(&:state)
end

#prevent_well_fail?(container) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/helpers/labware_helper.rb', line 35

def prevent_well_fail?(container)
  !container.passed?
end

#simple_state_change_form(presenter) ⇒ Object



8
9
10
# File 'app/helpers/labware_helper.rb', line 8

def simple_state_change_form(presenter)
  render partial: 'labware/simple_state_change', locals: { presenter: presenter }
end

#state_change_form(presenter) ⇒ Object



4
5
6
# File 'app/helpers/labware_helper.rb', line 4

def state_change_form(presenter)
  render partial: 'labware/state_change', locals: { presenter: presenter }
end