Module: Reading::Parsing::Attributes::Experiences::SpansValidator

Defined in:
lib/reading/parsing/attributes/experiences/spans_validator.rb

Overview

Methods to validate dates in spans. This does not cover all the ways dates can be invalid, just the ones not caught during parsing.

Class Method Summary collapse

Class Method Details

.validate(experiences, history_column: false) ⇒ Object

Checks the dates in the given experiences hash, and raises an error at the first invalid date found.

Parameters:

  • experiences (Array<Hash>)

    experience hashes.

  • history_column (Boolean) (defaults to: false)

    whether this validation is for experiences from the History column.

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/reading/parsing/attributes/experiences/spans_validator.rb', line 17

def validate(experiences, history_column: false)
  if both_date_columns? && !history_column
    validate_number_of_start_dates_and_end_dates(experiences)
  end

  if start_dates_column? || history_column
    validate_start_dates_are_in_order(experiences)
  end

  if end_dates_column? || history_column
    validate_end_dates_are_in_order(experiences)
  end

  if both_date_columns? || history_column
    validate_experiences_of_same_variant_do_not_overlap(experiences)
  end

  validate_spans_are_in_order_and_not_overlapping(experiences)
end