Class: TimeTable::TimeTableHelper::Timetable
- Inherits:
-
Object
- Object
- TimeTable::TimeTableHelper::Timetable
- Defined in:
- app/helpers/time_table/time_table_helper.rb
Instance Attribute Summary collapse
-
#clip_size ⇒ Object
Returns the value of attribute clip_size.
-
#clock_type ⇒ Object
Returns the value of attribute clock_type.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#frozen ⇒ Object
Returns the value of attribute frozen.
-
#segment_scale ⇒ Object
Returns the value of attribute segment_scale.
-
#segment_size ⇒ Object
Returns the value of attribute segment_size.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#initialize(date = nil, **options) ⇒ Timetable
constructor
A new instance of Timetable.
- #segments ⇒ Object
- #time_in_24_hour(time) ⇒ Object
- #time_in_meridian(time) ⇒ Object
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, **) @start_time = [:start_time] || 0 @end_time = [:end_time] || 1440 @start_time = date.beginning_of_day if date @end_time = date.end_of_day if date @segment_size = [:segment_size] || 60 @segment_scale = [:scale] || 100 @clip_size = [:clip_size] || 15 @clock_type = [:clock_type] || :meridian @frozen = [:frozen] || false end |
Instance Attribute Details
#clip_size ⇒ Object
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_type ⇒ Object
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_time ⇒ Object
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 |
#frozen ⇒ Object
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_scale ⇒ Object
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_size ⇒ Object
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_time ⇒ Object
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
#segments ⇒ Object
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 |