class TimeKeeper::Parser::Military

Constants

TIME_FORMAT_REGEX

Public Instance Methods

parse() click to toggle source
# File lib/time_keeper/parser/military.rb, line 8
def parse
  matched_data = @time_str.match(TimeKeeper::Parser::Military::TIME_FORMAT_REGEX)
  extract_hour(matched_data[1])
  extract_min(matched_data[4])
  self
end

Private Instance Methods

extract_hour(hour_of_day) click to toggle source
# File lib/time_keeper/parser/military.rb, line 24
def extract_hour(hour_of_day)
  @hour = (hour_of_day.strip.to_i || 0)
end
time_is_valid() click to toggle source
# File lib/time_keeper/parser/military.rb, line 17
def time_is_valid
  matched_data = @time_str.match(TimeKeeper::Parser::Military::TIME_FORMAT_REGEX)
  valid = ((0...24) === matched_data[1].to_i && (0...60) === matched_data[4].gsub(':', '').to_i)
  self.errors.add(:base, "Either hour or min is not valid") unless valid
  valid
end