Class: Carendar::Calendar

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, item_hashes) ⇒ Calendar

Returns a new instance of Calendar.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/carendar.rb', line 78

def initialize(from, to, item_hashes)
  items_by_day = item_hashes.group_by do |item_hash|
    item_hash[:starts_at].beginning_of_day
  end

  beginning_of_calendar = from.beginning_of_week
  end_of_calendar = to.end_of_week
  current_day = beginning_of_calendar
  @days = []
  while (current_day <= end_of_calendar) do
    @days << CalendarDay.new(current_day, items_by_day[current_day] || [])
    current_day += 1.day
  end
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



77
78
79
# File 'lib/carendar.rb', line 77

def days
  @days
end