class TimeKeeper::TimeRange

Constants

TIME_FORMAT_REGEX

Attributes

end_day[RW]
end_time[RW]
range[RW]
start_day[RW]
start_time[RW]

Public Class Methods

new(range) click to toggle source
# File lib/time_keeper/time_range.rb, line 10
def initialize(range)
  @range = range.strip.downcase.gsub(/\s*(-|to)\s*/, '-')
end

Public Instance Methods

days_elapsed() click to toggle source
# File lib/time_keeper/time_range.rb, line 24
def days_elapsed
  @start_time.in_seconds > @end_time.in_seconds ? 1 : 0
end
duration_in_hours() click to toggle source
# File lib/time_keeper/time_range.rb, line 36
def duration_in_hours
  ((duration_in_seconds.to_f/3600)*100).round.to_f/100
end
duration_in_minutes() click to toggle source
# File lib/time_keeper/time_range.rb, line 32
def duration_in_minutes
  ((duration_in_seconds.to_f/60)*100).round.to_f/100
end
duration_in_seconds() click to toggle source
# File lib/time_keeper/time_range.rb, line 28
def duration_in_seconds
  (days_elapsed * 24 * 60 * 60) + (@end_time.in_seconds - @start_time.in_seconds)
end
parse() click to toggle source
# File lib/time_keeper/time_range.rb, line 14
def parse
  raise "The range data (#{range.inspect}) you have provided is invalid" unless self.valid?
  parsed_range = @range.gsub('to', '-').split('-').map(&:strip)
  @start_time = TimeKeeper::CustomTime.new(parsed_range.first).parse
  @end_time = TimeKeeper::CustomTime.new(parsed_range.last).parse
  @start_day = 0
  @end_day = days_elapsed
  self
end