Module: RetentionInstructionHelper

Instance Method Summary collapse

Instance Method Details

#find_retention_instruction_from_key(key) ⇒ Object

Find the retention instruction value based on the key



9
10
11
12
13
# File 'app/helpers/retention_instruction_helper.rb', line 9

def find_retention_instruction_from_key(key)
  value = I18n.t("retention_instructions.#{key}")
  return nil if value.include?('Translation missing:')
  value
end

#find_retention_instruction_key_for_value(value) ⇒ Object

Retrieve the I18n key for a given value in the retention_instructions hash NB: Might not be an ideal way to do this, but it works for now.



17
18
19
20
# File 'app/helpers/retention_instruction_helper.rb', line 17

def find_retention_instruction_key_for_value(value)
  I18n.t(:retention_instructions).each { |key, val| return key if val.casecmp(value).zero? }
  nil
end

#find_retention_instruction_to_display(labware) ⇒ Object

This function is used to find the retention instruction to display for a given labware NB: The elsif statement in the function will not be necessary after the script in #4095 is run,. After the script in #4095 is run, the elsif branch can be removed.



25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/retention_instruction_helper.rb', line 25

def find_retention_instruction_to_display(labware)
   = labware.
  retention_instruction = labware.retention_instruction
  if retention_instruction.present?
    return retention_instruction
  elsif labware.custom_metadatum_collection.present? && .key?('retention_instruction')
    return find_retention_instruction_key_for_value(['retention_instruction'])
  end
  nil
end

#retention_instruction_option_for_selectObject

Return the retention instruction options for select



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

def retention_instruction_option_for_select
  Labware.retention_instructions.keys.map { |option| [I18n.t("retention_instructions.#{option}"), option] }
end