Class: Versed::ScheduleView
- Inherits:
-
Object
- Object
- Versed::ScheduleView
- Defined in:
- lib/versed/schedule_view.rb
Constant Summary collapse
- DAYS_PER_ROW =
8
Instance Method Summary collapse
-
#initialize(schedule) ⇒ ScheduleView
constructor
A new instance of ScheduleView.
- #to_hash ⇒ Object
Constructor Details
#initialize(schedule) ⇒ ScheduleView
Returns a new instance of ScheduleView.
8 9 10 |
# File 'lib/versed/schedule_view.rb', line 8 def initialize(schedule) @schedule = schedule end |
Instance Method Details
#to_hash ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/versed/schedule_view.rb', line 12 def to_hash hash = { "sections" => [], "metadata" => , "incomplete_tasks" => incomplete_tasks } # fill in days section = nil @schedule.days.each_with_index do |day, day_id| if day_id % DAYS_PER_ROW == 0 section = { "days" => [], "categories" => [] } hash["sections"] << section end section["days"] << day.date.strftime("%m.%d") end # determine row date ranges day_ranges = [] day_max = @schedule.days.size - 1 start_date = 0 while start_date <= day_max end_date = [start_date + DAYS_PER_ROW - 1, day_max].min day_ranges << (start_date..end_date) start_date = end_date + 1 end # fill in categories and tasks @schedule.categories.each do |category| day_ranges.each_with_index do |range, section_index| hash["sections"][section_index]["categories"] << category_hash(category, range) end end # create header origin = @schedule.days.first.date hash["header"] = "#{Date::MONTHNAMES[origin.month]} #{origin.year}" hash["sub_header"] = "Generated on #{Date.today}" hash end |