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
22
23
24
25
# 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


27
28
29
30
31
32
33
34
35
36
37
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 27

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


58
59
60
61
62
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 58

def add_columns
  columns.update(first_row, last_row, ranges, axlsx_worksheet)
  add_headers
  sample_manifest.details_array.each { |detail| create_row(detail) }
end

#add_multiplexed_library_tube_barcodeObject


103
104
105
106
107
108
109
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 103

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.


42
43
44
45
46
47
48
49
50
51
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 42

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


67
68
69
70
71
72
73
74
75
76
77
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 67

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


111
112
113
114
115
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 111

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)


94
95
96
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 94

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


82
83
84
85
86
87
88
89
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 82

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


99
100
101
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/data_worksheet.rb', line 99

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