Class: Labimotion::ImportElementVariations

Inherits:
Object
  • Object
show all
Defined in:
lib/labimotion/libs/import_element_variations.rb

Overview

ImportElementVariations Reads an .xlsx workbook produced by ExportElementVariations back into an element's variations.

Rows are merged by uuid: a sheet row updates only the columns the sheet actually carries, variations absent from the sheet are left untouched, and a row with a blank __uuid becomes a new variation. A wholesale replace would silently drop data held in columns the user had not selected when exporting.

Defined Under Namespace

Classes: InvalidWorkbook

Constant Summary collapse

SHEET_NAME =
'Variations'
KEY_ROW_SEARCH_LIMIT =

The machine key row is found by its __uuid cell rather than fixed at a row number, so a workbook from an older export -- whose header was one row instead of three -- still imports.

8
MULTI_VALUE_SEPARATOR =
';'
GROUP_DISALLOWED =
/[^a-zA-Z0-9_\-.,\s]/
GROUP_MAX_LENGTH =
64
REJECTED =

A cell whose value a column cannot hold. Treated like a blank cell: it clears what the column held, but never adds a value that was not there.

Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, file_path, segment_klasses: nil, record: nil) ⇒ ImportElementVariations

Returns a new instance of ImportElementVariations.



32
33
34
35
36
37
38
# File 'lib/labimotion/libs/import_element_variations.rb', line 32

def initialize(element, file_path, segment_klasses: nil, record: nil)
  @element = element
  @file_path = file_path
  @segment_klasses = segment_klasses
  @record = record
  @warnings = []
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



40
41
42
# File 'lib/labimotion/libs/import_element_variations.rb', line 40

def element
  @element
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



40
41
42
# File 'lib/labimotion/libs/import_element_variations.rb', line 40

def file_path
  @file_path
end

#warningsObject (readonly)

Returns the value of attribute warnings.



40
41
42
# File 'lib/labimotion/libs/import_element_variations.rb', line 40

def warnings
  @warnings
end

Instance Method Details

#execute!Object



42
43
44
45
46
47
# File 'lib/labimotion/libs/import_element_variations.rb', line 42

def execute!
  sheet = open_sheet
  mapping = build_column_mapping(sheet)
  parsed_rows = parse_rows(sheet, mapping)
  persist(parsed_rows)
end