Module: Emendate::Examples::DateTestable

Defined in:
lib/emendate/examples/date_testable.rb

Overview

Mixin module for Examples::Tester

Instance Method Summary collapse

Instance Method Details

#expected_resultObject



7
8
9
10
11
12
13
14
15
# File 'lib/emendate/examples/date_testable.rb', line 7

def expected_result
  return nil unless example.testable?

  example.rows
    .map { |row| row.send(name.to_sym) }
    .map { |val| val.start_with?("Date") ? instance_eval(val) : val }
    .map { |val| prep_expected(val) }
    .join("|")
end

#prep_expected(val) ⇒ Object



17
18
19
20
21
# File 'lib/emendate/examples/date_testable.rb', line 17

def prep_expected(val)
  return val unless name == "date_certainty"

  val.split(";").sort.join(";")
end

#tested_resultObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/emendate/examples/date_testable.rb', line 23

def tested_result
  return nil unless example.testable?
  return "nilValue" if example.processed.result.dates.empty?

  case name
  when "date_certainty"
    example.processed.result.dates
      .map { |date| date.send(:qualifiers) }
      .map do |arr|
      arr.empty? ? "nilValue" : arr.map(&:for_test)
        .sort
        .join(";")
    end
      .join("|")

  else
    example.processed.result.dates
      .map { |date| date.send(name) }
      .map { |date| date.nil? ? "nilValue" : date }
      .join("|")
  end
end