Method: Doing::WWID#repeat_item

Defined in:
lib/doing/wwid/modify.rb

#repeat_item(item, opt) ⇒ Object

Duplicate an item and add it as a new item

Parameters:

  • item (Item)

    the item to duplicate

  • opt (Hash)

    additional options

Options Hash (opt):

  • :editor (Boolean)

    open new item in editor

  • :date (String)

    set start date

  • :in (String)

    add new item to section :in

  • :note (Note)

    add note to new item

Returns:

  • nothing



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/doing/wwid/modify.rb', line 100

def repeat_item(item, opt)
  opt ||= {}
  old_item = item.clone
  if item.should_finish?
    if item.should_time?
      finish_date = verify_duration(item.date, Time.now, title: item.title)
      item.title.tag!('done', value: finish_date.strftime('%F %R'))
    else
      item.title.tag!('done')
    end
    Hooks.trigger :post_entry_updated, self, item, old_item
  end

  # Remove @done tag
  title = item.title.sub(/\s*@done(\(.*?\))?/, '').chomp
  section = opt[:in].nil? ? item.section : guess_section(opt[:in])
  Doing.auto_tag = false

  note = opt[:note] || Note.new

  if opt[:editor]
    start = opt[:date] ? opt[:date] : Time.now
    to_edit = "#{start.strftime('%F %R')} | #{title}"
    to_edit += "\n#{note.strip_lines.join("\n")}" unless note.empty?
    new_item = fork_editor(to_edit)
    date, title, note = format_input(new_item)

    opt[:date] = date unless date.nil?

    if title.nil? || title.empty?
      logger.warn('Skipped:', 'No content provided')
      return
    end
  end

  # @content.update_item(original, item)
  add_item(title, section, { note: note, back: opt[:date], timed: false })
end