class TimeRangeExtractor::Parser
Constants
- PATTERN
Public Class Methods
new(text, date: Date.current)
click to toggle source
# File lib/time_range_extractor/parser.rb, line 25 def initialize(text, date: Date.current) @text = text @date = date end
Public Instance Methods
call()
click to toggle source
# File lib/time_range_extractor/parser.rb, line 30 def call match = PATTERN.match(@text) result = MatchResult.new(match) return nil unless result.valid? time_range_from(result) end
Private Instance Methods
time_from_string(string)
click to toggle source
# File lib/time_range_extractor/parser.rb, line 53 def time_from_string(string) time_parser.parse(string, @date.to_time) end
time_parser()
click to toggle source
:reek: UtilityFunction so that we can optionally include ActiveSupport
# File lib/time_range_extractor/parser.rb, line 58 def time_parser ::Time.zone || ::Time end
time_range_from(match_result)
click to toggle source
# File lib/time_range_extractor/parser.rb, line 40 def time_range_from(match_result) start_time = time_from_string(match_result.start_time_string) end_time = time_from_string(match_result.end_time_string) if start_time <= end_time start_time..end_time elsif start_time > end_time start_time..(end_time + 1.day) end rescue ArgumentError nil end