class Colorgy::CoursePeriod::Period
Attributes
code[RW]
end_at[RW]
order[RW]
start_at[RW]
time[RW]
Public Class Methods
new(row)
click to toggle source
# File lib/colorgy/course_period/period.rb, line 6 def initialize(row) self.order, self.code, self.time = row self.order = order.to_i self.start_at, self.end_at = time.split('-').map { |s| ::Colorgy.time_class.parse(s) } validate_time end
Public Instance Methods
end_time(date)
click to toggle source
# File lib/colorgy/course_period/period.rb, line 25 def end_time(date) utc_format_str(merge_date(date, end_at)) end
start_time(date)
click to toggle source
# File lib/colorgy/course_period/period.rb, line 21 def start_time(date) utc_format_str(merge_date(date, start_at)) end
to_s()
click to toggle source
# File lib/colorgy/course_period/period.rb, line 29 def to_s { order: order, code: code, start_at: start_at, end_at: end_at }.to_s end
validate_time()
click to toggle source
# File lib/colorgy/course_period/period.rb, line 15 def validate_time # a full time string should match something like "10:10-11:30" time_regex = /\d{2}\:\d{2}\-\d{2}\:\d{2}/ raise InvalidTimeFormat unless time.match(time_regex) end
Private Instance Methods
date_time_args(date, time)
click to toggle source
# File lib/colorgy/course_period/period.rb, line 52 def date_time_args(date, time) [date.year, date.month, date.day, time.hour, time.min, time.sec] end
merge_date(date, time)
click to toggle source
# File lib/colorgy/course_period/period.rb, line 40 def merge_date(date, time) if ::Colorgy.time_class.method_defined?(:formatted_offset) DateTime.new(*date_time_args(date, time).append(time.formatted_offset)) else DateTime.new(*date_time_args(date, time)) end end
utc_format_str(time)
click to toggle source
# File lib/colorgy/course_period/period.rb, line 48 def utc_format_str(time) time.getutc.iso8601.gsub(/[-:]/, '') end