Class: Carendar::CalendarDay
- Inherits:
-
Object
- Object
- Carendar::CalendarDay
- Defined in:
- lib/carendar.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(day, items) ⇒ CalendarDay
constructor
A new instance of CalendarDay.
Constructor Details
#initialize(day, items) ⇒ CalendarDay
Returns a new instance of CalendarDay.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/carendar.rb', line 37 def initialize(day, items) @day = day @items = items.map do |item| CalendarItem.new(item[:starts_at], item[:ends_at], item[:options] || {}) end @items.sort_by!(&:start_min) @items.each do |item| item.overlapping_with_earlier = @items.select do |other| other.start_min < item.start_min && other.end_min > item.start_min end item.overlapping_with_later = [] item.offset_right = 0 end @items.each do |item| item.overlapping_with_earlier.each do |overlapper| overlapper.overlapping_with_later << item end end @items.each do |item| item.offset_left = if item.overlapping_with_earlier.any? item.overlapping_with_earlier.last.offset_left + 1 else 0 end end @items.reverse.each do |item| item.offset_right = if item.overlapping_with_later.present? item.overlapping_with_later.first.offset_right + 1 else 0 end end end |
Instance Attribute Details
#day ⇒ Object (readonly)
Returns the value of attribute day.
35 36 37 |
# File 'lib/carendar.rb', line 35 def day @day end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
35 36 37 |
# File 'lib/carendar.rb', line 35 def items @items end |