Class: CsvTemplateGenerator::TemplateSpec

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/csv_template_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheet_description: , field_name_text: , title_text: , columns: , # required fieldsgroup_text: false, description_text: false) ⇒ TemplateSpec

Allowed keys in column_spec: :title is a human-readable name for the column :description is a longer narrative description of the column. If any column has a :description, all columns MUST. Otherwise, the line will be omitted. :group is an arbitrary string used to group columns. If any column has a :group, all columns MUST. Otherwise, the line will be omitted. :blank means that the value should be left empty for the user to fill in :required means the value is required, ‘ (required)’ will be added to the column title :formatter is a callable that will be applied to the returned values from the database



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'backend/app/lib/csv_template_generator.rb', line 36

def initialize(sheet_description:, field_name_text:, title_text:, columns:, # required fields
               group_text: false, description_text: false)                # optional fields
  @sheet_description = sheet_description
  @field_name_text = field_name_text
  @title_text = title_text
  @columns = columns


  @group_text = group_text
  @description_text = description_text

  errors = []

  unless !!@group_text == @columns.values.all? {|col| Hash === col && col[:group] }
    errors << ":group_text value: #{group_text} and column values for :group do not agree, either add :group_text value or remove :group from columns as needed."
  end

  unless !!@description_text == columns.values.all? {|col| col.is_a?(Hash) && col[:description] }
    errors << ":description_text value: #{description_text} and column values for :description do not agree, either add :description_text value or remove :description from columns as needed."
  end

  if errors.count > 0
    raise CsvTemplateError, errors.join(" ")
  end
end

Instance Attribute Details

#columnsObject

Description of spreadsheet as a whole



10
11
12
# File 'backend/app/lib/csv_template_generator.rb', line 10

def columns
  @columns
end

#description_textObject

Description of spreadsheet as a whole



10
11
12
# File 'backend/app/lib/csv_template_generator.rb', line 10

def description_text
  @description_text
end

#field_name_textObject

Description of spreadsheet as a whole



10
11
12
# File 'backend/app/lib/csv_template_generator.rb', line 10

def field_name_text
  @field_name_text
end

#group_textObject

Description of spreadsheet as a whole



10
11
12
# File 'backend/app/lib/csv_template_generator.rb', line 10

def group_text
  @group_text
end

#sheet_descriptionObject

Description of spreadsheet as a whole



10
11
12
# File 'backend/app/lib/csv_template_generator.rb', line 10

def sheet_description
  @sheet_description
end

#title_textObject

Description of spreadsheet as a whole



10
11
12
# File 'backend/app/lib/csv_template_generator.rb', line 10

def title_text
  @title_text
end