Class: Dates::DateExtractor
- Inherits:
-
Object
- Object
- Dates::DateExtractor
- Defined in:
- lib/docfolio/paragraph_modules/dates.rb
Instance Method Summary collapse
-
#extract_date(paragraph_text, date) ⇒ Array<String, Array, Time>
The $LAST_MATCH_INFO global is equivalent to Rexexp.last_match and returns a MatchData object.
Instance Method Details
#extract_date(paragraph_text, date) ⇒ Array<String, Array, Time>
The $LAST_MATCH_INFO global is equivalent to Rexexp.last_match and returns a MatchData object. This can be used as an array, where indices 1 - n are the matched backreferences of the last successful match
- String return value
-
‘paragraph_text’ the same paragraph that was passed to the function but without the matched date character if there were any.
- Array return value
-
‘time_array’ array of 4 integer representing the hours and minutes of the from and to times
- Time return value
-
‘date’ the date in (day month year) of this paragraph taken from the matched date_regex if there was one. Will be nil if there was no match and if the date passed to the function was also nil.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/docfolio/paragraph_modules/dates.rb', line 94 def extract_date(paragraph_text, date) time_array = [] # if text contains a date match if date_regex =~ paragraph_text # $POSTMATCH (or $'), contains the characters after the match position paragraph_text = $POSTMATCH # strip whitespace if any remaining match or set to empty string # if no match. If there is just white space after the match then # this is truncated to an empty string paragraph_text.nil? ? paragraph_text = '' : paragraph_text.strip! # extracts the 'from' and 'to' times from the last match above. the # time_array contains from_hour, from_min, to_hour, to_min, the # date parameter is updated if the match found a new date time_array, date = date_from_globals($LAST_MATCH_INFO, date) end [paragraph_text, time_array, date] end |