Class: SpreeCmCommissioner::CalendarEvent

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_date:, to_date:, title: nil, options: nil) ⇒ CalendarEvent



5
6
7
8
9
10
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 5

def initialize(from_date:, to_date:, title: nil, options: nil)
  @from_date = from_date
  @to_date = to_date
  @title = title
  @options = options
end

Instance Attribute Details

#from_dateObject (readonly)

Returns the value of attribute from_date.



3
4
5
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 3

def from_date
  @from_date
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 3

def options
  @options
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 3

def title
  @title
end

#to_dateObject (readonly)

Returns the value of attribute to_date.



3
4
5
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 3

def to_date
  @to_date
end

Class Method Details

.from_inventory_items(inventory_items) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 27

def self.from_inventory_items(inventory_items)
  inventory_items.map do |item|
    CalendarEvent.new(
      from_date: item.inventory_date,
      to_date: item.inventory_date,
      options: { inventory_item: item }
    )
  end
end

.from_orders(orders) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spree_cm_commissioner/calendar_event.rb', line 12

def self.from_orders(orders)
  orders.map do |order|
    CalendarEvent.new(
      from_date: order.line_items.minimum(:from_date),
      to_date: order.line_items.maximum(:to_date),
      title: Spree.t(:order),
      options: {
        popover: 'shared/calendar/order_popover',
        classes: ['bg-primary'],
        order: order
      }
    )
  end
end