Class: SequencescapeExcel::Worksheet::Base
- Inherits:
-
Object
- Object
- SequencescapeExcel::Worksheet::Base
- Includes:
- ActiveModel::Model
- Defined in:
- app/sequencescape_excel/sequencescape_excel/worksheet/base.rb
Overview
Base class for worksheets
Direct Known Subclasses
BulkSubmissionExcel::Worksheet::DataWorksheet, SampleManifestExcel::Worksheet::DataWorksheet, SampleManifestExcel::Worksheet::TestWorksheet, RangesWorksheet
Instance Attribute Summary collapse
-
#axlsx_worksheet ⇒ Object
Returns the value of attribute axlsx_worksheet.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#name ⇒ Object
Assigns name to a worksheet depending on axlsx worksheet name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#ranges ⇒ Object
Returns the value of attribute ranges.
-
#workbook ⇒ Object
Returns the value of attribute workbook.
Instance Method Summary collapse
-
#add_row(values = [], style = nil, types = nil) ⇒ Object
Adds row to a worksheet with particular value, style and type for each cell.
-
#add_rows(num_rows) ⇒ Object
Adds n empty rows.
-
#create_worksheet ⇒ Object
Creates a worksheet, empty one in this case.
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
-
#insert_axlsx_worksheet(name, index = 0) ⇒ Object
Adds axlsx worksheet to a workbook, to a particular place.
-
#protect ⇒ Object
Protects worksheet, but sizes of rows and columns can be changed.
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 16 def initialize(attributes = {}) super create_worksheet protect if password.present? end |
Instance Attribute Details
#axlsx_worksheet ⇒ Object
Returns the value of attribute axlsx_worksheet.
13 14 15 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 13 def axlsx_worksheet @axlsx_worksheet end |
#columns ⇒ Object
Returns the value of attribute columns.
13 14 15 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 13 def columns @columns end |
#name ⇒ Object
Assigns name to a worksheet depending on axlsx worksheet name. Used to assign absolute references to ranges.
36 37 38 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 36 def name @name ||= axlsx_worksheet.name end |
#password ⇒ Object
Returns the value of attribute password.
13 14 15 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 13 def password @password end |
#ranges ⇒ Object
Returns the value of attribute ranges.
13 14 15 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 13 def ranges @ranges end |
#workbook ⇒ Object
Returns the value of attribute workbook.
13 14 15 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 13 def workbook @workbook end |
Instance Method Details
#add_row(values = [], style = nil, types = nil) ⇒ Object
Adds row to a worksheet with particular value, style and type for each cell
24 25 26 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 24 def add_row(values = [], style = nil, types = nil) axlsx_worksheet.add_row values, types: types || ([:string] * values.length), style: style end |
#add_rows(num_rows) ⇒ Object
Adds n empty rows
29 30 31 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 29 def add_rows(num_rows) num_rows.times { |_i| add_row } end |
#create_worksheet ⇒ Object
Creates a worksheet, empty one in this case
58 59 60 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 58 def create_worksheet insert_axlsx_worksheet(worksheet_name) end |
#insert_axlsx_worksheet(name, index = 0) ⇒ Object
Adds axlsx worksheet to a workbook, to a particular place.
52 53 54 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 52 def insert_axlsx_worksheet(name, index = 0) @axlsx_worksheet ||= workbook.insert_worksheet(index, name:) # rubocop:disable Naming/MemoizedInstanceVariableName end |
#protect ⇒ Object
Protects worksheet, but sizes of rows and columns can be changed
42 43 44 45 46 47 48 |
# File 'app/sequencescape_excel/sequencescape_excel/worksheet/base.rb', line 42 def protect axlsx_worksheet.sheet_protection do |sheet_protection| sheet_protection.format_columns = false sheet_protection.format_rows = false sheet_protection.password = password end end |