Class: Emendate::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/emendate/result.rb

Overview

Wrapper class around one or more ParsedDates.

Presents any errors and warnings from the date parsing process, along with the ProcessingManager and its detailed, step-by-step audit of the process.

The public API is loosely based on timetwister and should remain consistent with that tool.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pm) ⇒ Result

Returns a new instance of Result.

Parameters:

  • pm (Emendate::ProcessingManager)


32
33
34
35
36
37
38
39
# File 'lib/emendate/result.rb', line 32

def initialize(pm)
  @pm = pm
  @original_string = pm.orig_string
  @errors = map_errors
  @warnings = pm.warnings
  @set_type = pm.tokens.set_type
  @dates = create_parsed_dates
end

Instance Attribute Details

#datesArray<Emendate::ParsedDate> (readonly)

Returns:



27
28
29
# File 'lib/emendate/result.rb', line 27

def dates
  @dates
end

#errorsArray (readonly)

Returns information about why string was unable to be parsed successfully.

Returns:

  • (Array)

    information about why string was unable to be parsed successfully



22
23
24
# File 'lib/emendate/result.rb', line 22

def errors
  @errors
end

#original_stringString (readonly)

Returns the original string parsed to generate this Emendate::Result.

Returns:



17
18
19
# File 'lib/emendate/result.rb', line 17

def original_string
  @original_string
end

#pmEmendate::ProcessingManager (readonly)

Returns:

  • (Emendate::ProcessingManager)


29
30
31
# File 'lib/emendate/result.rb', line 29

def pm
  @pm
end

#set_typeObject (readonly)

Returns the value of attribute set_type.



19
20
21
# File 'lib/emendate/result.rb', line 19

def set_type
  @set_type
end

#warningsArray (readonly)

Returns information about how ambiguous date options or other settings were applied.

Returns:

  • (Array)

    information about how ambiguous date options or other settings were applied.



25
26
27
# File 'lib/emendate/result.rb', line 25

def warnings
  @warnings
end

Instance Method Details

#compile_date_info(method:, delim:) ⇒ String

Returns concatenated result of calling method on all the dates.

Parameters:

  • method (Symbol)

    name of ParsedDate public method

  • delim (String)

    for joining multiple values

Returns:

  • (String)

    concatenated result of calling method on all the dates



44
45
46
# File 'lib/emendate/result.rb', line 44

def compile_date_info(method:, delim:)
  dates.map(&method).join(delim)
end

#date_countInteger

Returns:

  • (Integer)


49
50
51
# File 'lib/emendate/result.rb', line 49

def date_count
  dates.length
end

#to_hHash

Returns representation of Emendate::Result.

Returns:



54
55
56
57
58
59
60
61
# File 'lib/emendate/result.rb', line 54

def to_h
  {
    original_string: original_string,
    dates: dates.map(&:to_h),
    errors: errors,
    warnings: warnings
  }
end

#to_jsonString

Returns:

  • (String)


64
65
66
# File 'lib/emendate/result.rb', line 64

def to_json
  to_h.to_json
end