Class: SequencescapeExcel::ColumnList
- Inherits:
-
Object
- Object
- SequencescapeExcel::ColumnList
show all
- Includes:
- ActiveModel::Validations, List
- Defined in:
- app/sequencescape_excel/sequencescape_excel/column_list.rb
Overview
Instance Method Summary
collapse
Methods included from List
#<=>, #add, #add_copy, #each, #find, #find_by, #items, #reset!, #values
Constructor Details
#initialize(columns = {}, conditional_formattings = {}) {|_self| ... } ⇒ ColumnList
To create a column_list a hash with details of all columns is required. Each key is a column name, each value is options for the column including heading, validation, conditional formatting rules, etc. for each column a new Column object is created. Each conditional formatting for the column is combined with its conditional formatting in the list. If the column is not valid an error is returned.
22
23
24
25
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 22
def initialize(columns = {}, conditional_formattings = {})
create_columns(columns || {}, conditional_formattings)
yield self if block_given?
end
|
Instance Method Details
#add_with_number(column, column_list = nil) ⇒ Object
58
59
60
61
62
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 58
def add_with_number(column, column_list = nil)
column.number = (column_list || self).next_number
add column
self
end
|
#bad_keys ⇒ Object
54
55
56
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 54
def bad_keys
@bad_keys ||= []
end
|
#column_values(replacements = {}) ⇒ Object
27
28
29
30
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 27
def column_values(replacements = {})
replacements.each { |k, v| find(k).value = v }
columns.collect(&:value)
end
|
#except(key) ⇒ Object
44
45
46
47
48
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 44
def except(key)
keys = names.dup
keys.delete(key.to_s)
(keys)
end
|
Extracts columns from a column list based on names (a list of columns names). Returns a new column list that consists only of the columns named in names.
35
36
37
38
39
40
41
42
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 35
def (keys)
ColumnList.new do |column_list|
keys.each do |key|
column = find(key)
column.present? ? column_list.add_with_number(column.dup, column_list) : column_list.bad_keys << key
end
end
end
|
#find_column_or_null(key, value) ⇒ Object
83
84
85
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 83
def find_column_or_null(key, value)
find_by(key, value) || SequencescapeExcel::NullObjects::NullColumn.new
end
|
#initialize_dup(source) ⇒ Object
77
78
79
80
81
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 77
def initialize_dup(source)
reset!
create_columns(source.columns, nil)
super
end
|
#inspect ⇒ Object
95
96
97
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 95
def inspect
"<#{self.class}: @columns:#{columns.map(&:name).inspect}...>"
end
|
#next_number ⇒ Object
Returns a number of a next column based on the number of columns that already exist in the list
67
68
69
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 67
def next_number
columns.count + 1
end
|
#update(first_row, last_row, ranges, worksheet) ⇒ Object
A forwarding method - Update each column in the list of columns.
73
74
75
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 73
def update(first_row, last_row, ranges, worksheet)
each { |column| column.update(first_row, last_row, ranges, worksheet) }
end
|
#with(key) ⇒ Object
50
51
52
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 50
def with(key)
add_with_number(Column.new(name: key, heading: key.to_s))
end
|
91
92
93
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 91
def with_metadata_fields
select(&:metadata_field?)
end
|
#with_specialised_fields ⇒ Object
87
88
89
|
# File 'app/sequencescape_excel/sequencescape_excel/column_list.rb', line 87
def with_specialised_fields
select(&:specialised_field?)
end
|