Class: Pello::Actions::MoveCard

Inherits:
Object
  • Object
show all
Defined in:
lib/pello/actions/move_card.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt, logger = Pello::CardLogger.new) ⇒ MoveCard



8
9
10
11
# File 'lib/pello/actions/move_card.rb', line 8

def initialize(prompt, logger = Pello::CardLogger.new)
  @prompt = prompt
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/pello/actions/move_card.rb', line 6

def logger
  @logger
end

#promptObject (readonly)

Returns the value of attribute prompt.



6
7
8
# File 'lib/pello/actions/move_card.rb', line 6

def prompt
  @prompt
end

Instance Method Details

#run(user, board_url, list_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pello/actions/move_card.rb', line 13

def run(user, board_url, list_name)
  board = Pello::Inputs.choose_board user, board_url
  return unless board

  puts board.as_table
  continue = true
  while continue
    source_list = Pello::Inputs.choose_list board, list_name, 'Choose source list'
    return unless source_list

    card = Pello::Inputs.choose_card source_list
    next unless card

    target_list = Pello::Inputs.choose_list board, list_name, 'Choose target list'
    return unless target_list && target_list != source_list

    puts "Moving card #{card.name} from \"#{source_list.name}\" to \"#{target_list.name}\""

    if prompt.yes?('Confirm?')
      card.list_id = target_list.id
      card.save
      logger.log user, card, "[#{Time.now}] #{card.extract_name} (#{source_list.name} -> #{target_list.name})"
      puts('Done!')
    else
      puts 'Ok, bye!'
      nil
    end

    continue = prompt.yes?('Another one?')
  end
end