0

我有一个复杂的范围,我正在获取一份清单。在这个清单中有一堆不同类别下的任务。我只想要完整的清单,但有些清单将是完整的,而不是每个类别都完成。因此,在检查列中是否包含任何内容之前,我需要能够检查是否需要每一列。这是我的例子。

scope :complete, lambda {|check_lists| check_lists.map do |check_list|
    not_complete = false

    if check_list.event.booking.video_for_event?
        if check_list.raw_footage_user_id.blank? && check_list.raw_footage_check.blank? then not_complete = true end    
    end

    if check_list.event.booking.eblast_not_blank?
      # more checking...
    end

    if check_list.event.booking.on_site_not_blank?
      # more checking...
    end

    if not_complete then reject end
end } #If videos, verify video items. if eblasts, verify eblast items, etc...

所以基本上我需要知道如何通过从正在映射的数组中删除 non_complete 对象来完成它。

4

1 回答 1

0

如果我清楚地理解你只想要完整的清单

基本上你必须在它为真时返回检查表,当它不是时返回 nil,然后用 compact 消除结果数组中的 nil... 这是 select 的工作

checklists.map do |checklist| 
  # ....
  checklist unless not_completed
end.compact

或更简洁地说:

checklists.select do |checklist| 
  # ....
  !not_completed
end
于 2013-07-02T13:57:04.310 回答