Class: SequencescapeExcel::Worksheet::DataWorksheet
- Includes:
- Helpers::Worksheet
- Defined in:
- app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb
Overview
DataWorksheet creates a data worksheet to be filled in by a client.
Constant Summary
Constants included from Helpers::Worksheet
Instance Attribute Summary collapse
-
#sample_manifest ⇒ Object
Returns the value of attribute sample_manifest.
- #type ⇒ Object
Attributes inherited from 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_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.
-
#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.
- #find_multiplexed_library_tube_barcode ⇒ Object
-
#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 Helpers::Worksheet
#add_headers, #create_styles, #first_row, #styles
Methods inherited from 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 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 15 def initialize(attributes = {}) super 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/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 8 def sample_manifest @sample_manifest end |
#type ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 24 def type @type ||= case sample_manifest.asset_type when '1dtube', 'multiplexed_library', 'library' 'Tubes' when 'plate' 'Plates' else '' end end |
Instance Method Details
#add_columns ⇒ Object
Adds columns with all required data to a worksheet
54 55 56 57 58 59 60 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 54 def add_columns columns.update(first_row, last_row, ranges, axlsx_worksheet) add_headers sample_manifest.details_array.each do |detail| create_row(detail) end end |
#add_multiplexed_library_tube_barcode ⇒ Object
101 102 103 104 105 106 107 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 101 def if sample_manifest.asset_type == 'multiplexed_library' add_row ['Multiplexed library tube barcode:', ] 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.
38 39 40 41 42 43 44 45 46 47 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 38 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_rows(1) 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 65 def create_row(detail) axlsx_worksheet.add_row do |row| columns.each do |column| if column.unlocked? row.add_cell column.attribute_value(detail), type: column.type, style: styles[:unlocked].reference else row.add_cell column.attribute_value(detail), type: column.type end end end end |
#find_multiplexed_library_tube_barcode ⇒ Object
109 110 111 112 113 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 109 def Tube.(sample_manifest.).first.requests.first.target_asset. rescue StandardError '' 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)
92 93 94 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 92 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
80 81 82 83 84 85 86 87 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 80 def freeze_panes(name = :sanger_sample_id) axlsx_worksheet.sheet_view.pane do |pane| pane.state = :frozen pane.y_split = 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
97 98 99 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 97 def last_row @last_row ||= sample_manifest.details_array.count + first_row - 1 end |