Class: SequencescapeExcel::Worksheet::DataWorksheet

Inherits:
Base
  • Object
show all
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

Helpers::Worksheet::STYLES

Instance Attribute Summary collapse

Attributes inherited from Base

#axlsx_worksheet, #columns, #name, #password, #ranges, #workbook

Instance Method Summary collapse

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
# 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_manifestObject

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

#typeObject


23
24
25
26
27
28
29
30
31
32
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 23

def type
  @type ||= case sample_manifest.asset_type
            when '1dtube', 'multiplexed_library', 'library'
              'Tubes'
            when 'plate'
              'Plates'
            else
              ''
            end
end

Instance Method Details

#add_columnsObject

Adds columns with all required data to a worksheet


53
54
55
56
57
58
59
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 53

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_barcodeObject


100
101
102
103
104
105
106
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 100

def add_multiplexed_library_tube_barcode
  if sample_manifest.asset_type == 'multiplexed_library'
    add_row ['Multiplexed library tube barcode:', find_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.


37
38
39
40
41
42
43
44
45
46
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 37

def add_title_and_description(study, supplier, count)
  add_row ['DNA Collections Form']
  add_rows(2)
  add_multiplexed_library_tube_barcode

  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


64
65
66
67
68
69
70
71
72
73
74
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 64

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_barcodeObject


108
109
110
111
112
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 108

def find_multiplexed_library_tube_barcode
  Tube.with_barcode(sample_manifest.barcodes).first.requests.first.target_asset.human_barcode
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)


91
92
93
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 91

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


79
80
81
82
83
84
85
86
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 79

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_rowObject

The row where the table with data end


96
97
98
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 96

def last_row
  @last_row ||= sample_manifest.details_array.count + first_row - 1
end