Class: SampleManifestExcel::Worksheet::DataWorksheet
- Inherits:
-
SequencescapeExcel::Worksheet::Base
- Object
- SequencescapeExcel::Worksheet::Base
- SampleManifestExcel::Worksheet::DataWorksheet
- Includes:
- SequencescapeExcel::Helpers::Worksheet
- Defined in:
- app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb
Overview
DataWorksheet creates a data worksheet to be filled in by a client.
Constant Summary
Constants included from SequencescapeExcel::Helpers::Worksheet
SequencescapeExcel::Helpers::Worksheet::STYLES
Instance Attribute Summary collapse
-
#sample_manifest ⇒ Object
Returns the value of attribute sample_manifest.
-
#type ⇒ Object
rubocop:todo Metrics/MethodLength.
Attributes inherited from SequencescapeExcel::Worksheet::Base
#axlsx_worksheet, #columns, #name, #password, #ranges, #workbook
Instance Method Summary collapse
-
#add_columns ⇒ Object
Adds columns with all required data to a worksheet.
- #add_extra_cells_for_tube_rack(count) ⇒ Object
- #add_multiplexed_library_tube_barcode ⇒ Object
-
#add_title_and_description(study, supplier, count) ⇒ Object
Adds title and description (study abbreviation, supplier name, number of assets sent) to a worksheet.
- #computed_first_row ⇒ Object
-
#create_row(detail) ⇒ Object
Creates row filled in with required column values, also unlocks (adds unlock style) the cells that should be filled in by clients.
-
#freeze_after_column(name) ⇒ Object
Finds the column after which the panes should be frozen.
-
#freeze_panes(name = :sanger_sample_id) ⇒ Object
Freezes panes vertically after particular column (sanger_sample_id by default) and horizontally after headings.
-
#initialize(attributes = {}) ⇒ DataWorksheet
constructor
A new instance of DataWorksheet.
-
#last_row ⇒ Object
The row where the table with data end.
Methods included from SequencescapeExcel::Helpers::Worksheet
#add_headers, #create_styles, #find_or_create_style, #first_row, #styles
Methods inherited from SequencescapeExcel::Worksheet::Base
#add_row, #add_rows, #create_worksheet, #insert_axlsx_worksheet, #protect
Constructor Details
#initialize(attributes = {}) ⇒ DataWorksheet
Returns a new instance of DataWorksheet.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 15 def initialize(attributes = {}) super @extra_rows_added = 0 create_styles add_title_and_description( sample_manifest.study.abbreviation, sample_manifest.supplier.name, sample_manifest.count ) add_columns freeze_panes end |
Instance Attribute Details
#sample_manifest ⇒ Object
Returns the value of attribute sample_manifest.
8 9 10 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 8 def sample_manifest @sample_manifest end |
#type ⇒ Object
rubocop:todo Metrics/MethodLength
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 28 def type # rubocop:todo Metrics/MethodLength @type ||= case sample_manifest.asset_type when '1dtube', 'multiplexed_library', 'library' 'Tubes' when 'plate' 'Plates' when 'tube_rack' 'Tube Racks' else '' end end |
Instance Method Details
#add_columns ⇒ Object
Adds columns with all required data to a worksheet
74 75 76 77 78 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 74 def add_columns columns.update(computed_first_row, last_row, ranges, axlsx_worksheet) add_headers sample_manifest.details_array.each { |detail| create_row(detail) } end |
#add_extra_cells_for_tube_rack(count) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 57 def add_extra_cells_for_tube_rack(count) rack_size = sample_manifest.tube_rack_purpose.size add_row ['Rack size:', rack_size] count.times do |num| axlsx_worksheet.add_row do |row| row.add_cell "Rack barcode (#{num + 1}):", type: :string row.add_cell nil, type: :string, style: styles[:unlocked_no_border].reference end end @extra_rows_added += count + 1 end |
#add_multiplexed_library_tube_barcode ⇒ Object
120 121 122 123 124 125 126 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 120 def if sample_manifest.asset_type == 'multiplexed_library' add_row ['Multiplexed library tube barcode:', sample_manifest.labware.first.] else add_row end end |
#add_title_and_description(study, supplier, count) ⇒ Object
Adds title and description (study abbreviation, supplier name, number of assets sent) to a worksheet.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 45 def add_title_and_description(study, supplier, count) add_row ['DNA Collections Form'] add_rows(2) add_row ['Study:', study] add_row ['Supplier:', supplier] add_row ["No. #{type} Sent:", count] add_extra_cells_for_tube_rack(count) if type == 'Tube Racks' add_rows(1) end |
#computed_first_row ⇒ Object
128 129 130 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 128 def computed_first_row type == 'Tube Racks' ? first_row + @extra_rows_added : first_row end |
#create_row(detail) ⇒ Object
Creates row filled in with required column values, also unlocks (adds unlock style) the cells that should be filled in by clients
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 83 def create_row(detail) axlsx_worksheet.add_row do |row| columns.each do |column| # If the row is invalid in the manifest, the cell should be locked style_name = (sample_manifest.invalid_wells&.include?(detail.fetch(:position, nil)) ? [:disabled] : column.style) style = find_or_create_style(style_name)&.reference row.add_cell column.attribute_value(detail), type: column.type, style: style end end end |
#freeze_after_column(name) ⇒ Object
Finds the column after which the panes should be frozen. If the column was not found freezes the panes after column 0 (basically not frozen vertically)
111 112 113 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 111 def freeze_after_column(name) columns.find_by(:name, name) ? columns.find_by(:name, name).number : 0 end |
#freeze_panes(name = :sanger_sample_id) ⇒ Object
Freezes panes vertically after particular column (sanger_sample_id by default) and horizontally after headings
99 100 101 102 103 104 105 106 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 99 def freeze_panes(name = :sanger_sample_id) axlsx_worksheet.sheet_view.pane do |pane| pane.state = :frozen pane.y_split = computed_first_row - 1 pane.x_split = freeze_after_column(name) pane.active_pane = :bottom_right end end |
#last_row ⇒ Object
The row where the table with data end
116 117 118 |
# File 'app/sample_manifest_excel/sample_manifest_excel/worksheet/data_worksheet.rb', line 116 def last_row @last_row ||= sample_manifest.details_array.count + computed_first_row - 1 end |