Class: Emendate::Result
- Inherits:
-
Object
- Object
- Emendate::Result
- 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
- #dates ⇒ Array<Emendate::ParsedDate> readonly
-
#errors ⇒ Array
readonly
Information about why string was unable to be parsed successfully.
-
#original_string ⇒ String
readonly
The original string parsed to generate this Result.
- #pm ⇒ Emendate::ProcessingManager readonly
-
#set_type ⇒ Object
readonly
Returns the value of attribute set_type.
-
#warnings ⇒ Array
readonly
Information about how ambiguous date options or other settings were applied.
Instance Method Summary collapse
-
#compile_date_info(method:, delim:) ⇒ String
Concatenated result of calling method on all the dates.
- #date_count ⇒ Integer
-
#initialize(pm) ⇒ Result
constructor
A new instance of Result.
-
#to_h ⇒ Hash
Representation of Result.
- #to_json ⇒ String
Constructor Details
#initialize(pm) ⇒ Result
Returns a new instance of Result.
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
#dates ⇒ Array<Emendate::ParsedDate> (readonly)
27 28 29 |
# File 'lib/emendate/result.rb', line 27 def dates @dates end |
#errors ⇒ Array (readonly)
Returns 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_string ⇒ String (readonly)
Returns the original string parsed to generate this Emendate::Result.
17 18 19 |
# File 'lib/emendate/result.rb', line 17 def original_string @original_string end |
#pm ⇒ Emendate::ProcessingManager (readonly)
29 30 31 |
# File 'lib/emendate/result.rb', line 29 def pm @pm end |
#set_type ⇒ Object (readonly)
Returns the value of attribute set_type.
19 20 21 |
# File 'lib/emendate/result.rb', line 19 def set_type @set_type end |
#warnings ⇒ Array (readonly)
Returns 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.
44 45 46 |
# File 'lib/emendate/result.rb', line 44 def compile_date_info(method:, delim:) dates.map(&method).join(delim) end |
#date_count ⇒ Integer
49 50 51 |
# File 'lib/emendate/result.rb', line 49 def date_count dates.length end |
#to_h ⇒ Hash
Returns representation of Emendate::Result.
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_json ⇒ String
64 65 66 |
# File 'lib/emendate/result.rb', line 64 def to_json to_h.to_json end |