Class: Reading::Parsing::Attributes::Experiences::HistoryTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/reading/parsing/attributes/experiences/history_transformer.rb

Overview

Experiences#transform_from_parsed delegates to this class when the History column is not blank (i.e. when experiences should be extracted from History and not the Start Dates, End Dates, and Head columns).

Instance Method Summary collapse

Constructor Details

#initialize(parsed_row, head_index) ⇒ HistoryTransformer

Returns a new instance of HistoryTransformer.

Parameters:

  • parsed_row (Hash)

    a parsed row (the intermediate hash).

  • head_index (Integer)

    current item’s position in the Head column.



34
35
36
37
38
# File 'lib/reading/parsing/attributes/experiences/history_transformer.rb', line 34

def initialize(parsed_row, head_index)
  @parsed_row = parsed_row
  @head_index = head_index
  @next_open_range_id = 0
end

Instance Method Details

#transformArray<Hash>

Extracts experiences from the parsed row.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/reading/parsing/attributes/experiences/history_transformer.rb', line 43

def transform
  experiences = parsed_row[:history].map { |entries|
    {
      spans: spans_from_history_entries(entries),
      group: entries.first[:group],
      variant_index: (entries.first[:variant] || 1).to_i - 1,
    }
  }

  Experiences::SpansValidator.validate(experiences, history_column: true)

  experiences
end