module Hizuke::DynamicPatternMatcher
def check_days_patterns(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_days_patterns(text) check_in_x_days_pattern(text) || check_x_days_ago_pattern(text) end
def check_dynamic_patterns(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_dynamic_patterns(text) # Try each pattern type check_days_patterns(text) || check_weeks_patterns(text) || check_months_patterns(text) || check_years_patterns(text) end
def check_in_x_days_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_in_x_days_pattern(text) if (match = text.match(IN_X_DAYS_PATTERN)) days = match[1].to_i date = Date.today + days clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_in_x_months_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_in_x_months_pattern(text) if (match = text.match(IN_X_MONTHS_PATTERN)) months = match[1].to_i date = Date.today >> months clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_in_x_weeks_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_in_x_weeks_pattern(text) if (match = text.match(IN_X_WEEKS_PATTERN)) weeks = match[1].to_i date = Date.today + (weeks * 7) clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_in_x_years_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_in_x_years_pattern(text) if (match = text.match(IN_X_YEARS_PATTERN)) years = match[1].to_i date = Date.new(Date.today.year + years, Date.today.month, Date.today.day) clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_months_patterns(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_months_patterns(text) check_in_x_months_pattern(text) || check_x_months_ago_pattern(text) end
def check_weeks_patterns(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_weeks_patterns(text) check_in_x_weeks_pattern(text) || check_x_weeks_ago_pattern(text) end
def check_x_days_ago_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_x_days_ago_pattern(text) if (match = text.match(X_DAYS_AGO_PATTERN)) days = match[1].to_i date = Date.today - days clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_x_months_ago_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_x_months_ago_pattern(text) if (match = text.match(X_MONTHS_AGO_PATTERN)) months = match[1].to_i date = Date.today << months clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_x_weeks_ago_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_x_weeks_ago_pattern(text) if (match = text.match(X_WEEKS_AGO_PATTERN)) weeks = match[1].to_i date = Date.today - (weeks * 7) clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_x_years_ago_pattern(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_x_years_ago_pattern(text) if (match = text.match(X_YEARS_AGO_PATTERN)) years = match[1].to_i date = Date.new(Date.today.year - years, Date.today.month, Date.today.day) clean_text = text.gsub(match[0], '').strip return Result.new(clean_text, date) end nil end
def check_years_patterns(text)
-
(Hizuke::Result, nil)
- the result or nil if no match
Parameters:
-
text
(String
) -- the text to check
def check_years_patterns(text) check_in_x_years_pattern(text) || check_x_years_ago_pattern(text) end