Class: Emendate::FormatStandardizer
- Inherits:
-
Object
- Object
- Emendate::FormatStandardizer
- Includes:
- DateUtils
- Defined in:
- lib/emendate/format_standardizer.rb
Overview
TODO:
Clean all date part tagging and date segmentation (i.e. creation of date type objects) from this step
Makes the format of date patterns more consistent.
Collapses some segments (e.g. comma in “Jan 1, 2000”).
Adds blank-lexeme segments (e.g. changing “Jan 2-5 2000” to “Jan 2 2000 - Jan 5 2000). These add the necessary type and literal information without changing the lexeme value.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tokens) ⇒ FormatStandardizer
constructor
A new instance of FormatStandardizer.
Methods included from DateUtils
#expand_shorter_digits, #is_range?, #max_season, #min_season, #month_abbr_literal, #month_literal, #possible_range?, #valid_date?, #valid_day?, #valid_month?, #valid_month_or_season?, #valid_season?, #valid_year?
Constructor Details
#initialize(tokens) ⇒ FormatStandardizer
Returns a new instance of FormatStandardizer.
24 25 26 |
# File 'lib/emendate/format_standardizer.rb', line 24 def initialize(tokens) @result = Emendate::SegmentSet.new.copy(tokens) end |
Class Method Details
.call ⇒ Object
19 20 21 |
# File 'lib/emendate/format_standardizer.rb', line 19 def call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/emendate/format_standardizer.rb', line 28 def call while standardizable function = determine_standardizer break if function.nil? pre = result.types.dup function.call TokenCollapser.call(result).either( ->(success) { @result = success }, ->(failure) { next } ) break if result.types == pre end Success(result) end |