fork download
  1. def months_with_items
  2. # Create a hash like
  3. # {"January" => [<OrderLineItem>, <OrderLineItem>], "February" => [...]}
  4. @months_with_items ||= (1..12).to_a.each_with_object({}) do |month_num, obj|
  5. tmp_date = Date.new(@date.shipped_at_min.year, month_num, 1)
  6.  
  7. month_fulfillments = fulfillments.select do |f|
  8. f.shipped_between?(tmp_date.beginning_of_month, tmp_date.end_of_month.end_of_day)
  9. end
  10.  
  11. month_fulfillment_line_item_ids = month_fulfillments.map do |f|
  12. f.fulfillment_line_item_ids
  13. end.flatten
  14.  
  15. month_fulfillment_line_items = fulfillment_line_items.select do |i|
  16. month_fulfillment_line_item_ids.include?(i.id)
  17. end
  18.  
  19. month_order_line_item_ids = month_fulfillment_line_items.map do |f|
  20. f.order_line_item_id
  21. end
  22.  
  23. month = Date::MONTHNAMES[month_num]
  24. obj[month] = order_line_items.select{|i| month_order_line_item_ids.include?(i.id)}
  25. end
  26. end
Success #stdin #stdout 0.01s 7416KB
stdin
Standard input is empty
stdout
Standard output is empty