Class: TimeTable::TimeTableHelper::Timetable

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/time_table/time_table_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = nil, **options) ⇒ Timetable

Returns a new instance of Timetable.



17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/time_table/time_table_helper.rb', line 17

def initialize(date = nil, **options)
  @start_time = options[:start_time] || 0
  @end_time = options[:end_time] || 1440
  @start_time = date.beginning_of_day if date
  @end_time = date.end_of_day if date
  @segment_size = options[:segment_size] || 60
  @segment_scale = options[:scale] || 100
  @clip_size = options[:clip_size] || 15
  @clock_type = options[:clock_type] || :meridian
  @frozen = options[:frozen] || false
end

Instance Attribute Details

#clip_sizeObject

Returns the value of attribute clip_size.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def clip_size
  @clip_size
end

#clock_typeObject

Returns the value of attribute clock_type.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def clock_type
  @clock_type
end

#end_timeObject

Returns the value of attribute end_time.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def end_time
  @end_time
end

#frozenObject

Returns the value of attribute frozen.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def frozen
  @frozen
end

#segment_scaleObject

Returns the value of attribute segment_scale.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def segment_scale
  @segment_scale
end

#segment_sizeObject

Returns the value of attribute segment_size.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def segment_size
  @segment_size
end

#start_timeObject

Returns the value of attribute start_time.



15
16
17
# File 'app/helpers/time_table/time_table_helper.rb', line 15

def start_time
  @start_time
end

Instance Method Details

#segmentsObject



29
30
31
32
33
34
35
36
37
# File 'app/helpers/time_table/time_table_helper.rb', line 29

def segments
  @start_time.step(@end_time, @segment_size).map do |time|
    if @clock_type == :meridian
      time_in_meridian(time)
    else
      time_in_24_hour(time)
    end
  end
end

#time_in_24_hour(time) ⇒ Object



48
49
50
51
52
# File 'app/helpers/time_table/time_table_helper.rb', line 48

def time_in_24_hour(time)
  hour = time / 60
  minute = time % 60
  "#{format('%02d', hour)}:#{format('%02d', minute)}"
end

#time_in_meridian(time) ⇒ Object



39
40
41
42
43
44
45
46
# File 'app/helpers/time_table/time_table_helper.rb', line 39

def time_in_meridian(time)
  hour = time / 60
  minute = time % 60
  period = hour < 12 ? "AM" : "PM"
  hour = hour % 12
  hour = 12 if hour == 0
  "#{hour}:#{format('%02d', minute)} #{period}"
end