class TimeRangeExtractor::MatchResult

Attributes

match_data[R]

Public Class Methods

new(match_data) click to toggle source
# File lib/time_range_extractor/match_result.rb, line 5
def initialize(match_data)
  @match_data = match_data
end

Public Instance Methods

end_period() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 27
def end_period
  match_data[:end_period]
end
end_time() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 23
def end_time
  match_data[:end_time]
end
end_time_string() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 39
def end_time_string
  [end_time, end_period, time_zone].compact.join(' ')
end
start_period() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 17
def start_period
  @start_period ||= match_data[:start_period].presence || begin
    force_start_period_to_am? ? 'am' : end_period
  end
end
start_time() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 13
def start_time
  match_data[:start_time]
end
start_time_string() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 35
def start_time_string
  [start_time, start_period, time_zone].compact.join(' ')
end
time_zone() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 31
def time_zone
  match_data[:time_zone]
end
valid?() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 9
def valid?
  @match_data && (start_time.present? && end_time.present?)
end

Private Instance Methods

force_start_period_to_am?() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 49
def force_start_period_to_am?
  start_t = start_time.to_i
  end_t = end_time.to_i

  end_period.casecmp('pm') == 0 &&
    (start_t > end_t || (end_t == 12 && start_t < end_t))
end
range?() click to toggle source
# File lib/time_range_extractor/match_result.rb, line 45
def range?
  start_time.present? && end_time.present?
end