Class: Sirius::TimeConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/sirius/time_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(hour_starts:, hour_length:) ⇒ TimeConverter

Initializes converter with timetable parameters required for conversion.

Parameters:

  • hour_starts (Array)

    Times when hours of schedule starts.

  • hour_length (Float)

    Duration of single teaching hour in minutes.


12
13
14
15
# File 'lib/sirius/time_converter.rb', line 12

def initialize( hour_starts:, hour_length:)
  @hour_starts = hour_starts
  @hour_length = hour_length
end

Instance Method Details

#convert_time(start_hour, duration) ⇒ Period

Converts hour data from KOSapi to real start and end time.

Examples:

Calculation with parameters:

start_hour = 5
duration = 2
@first_hour = 7:30
@hour_length = 45m
@break_length = 15m
@break_after = 2

start_time = 7:30 + (5-1)*45m + ((5-1)/2)*15m = 7:30 + 180m + 30m = 11:00
end_time = 11:00 + 90m = 12:45

Parameters:

  • start_hour (Integer)

    Hour number when the event starts

  • duration (Integer)

    Event duration in whole teaching hours

Returns:

  • (Period)

    Event start and end times


34
35
36
37
38
39
# File 'lib/sirius/time_converter.rb', line 34

def convert_time( start_hour, duration )
  raise "Invalid start hour (#{start_hour}) or duration (#{duration})" if start_hour <= 0 || duration <= 0
  start_time = @hour_starts[start_hour - 1]
  end_time = start_time + (@hour_length * duration).minutes
  Period.new(start_time, end_time)
end