Class: Tagger

Inherits:
Object
  • Object
show all
Defined in:
lib/moneymanager/tagger.rb

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



2
3
4
# File 'lib/moneymanager/tagger.rb', line 2

def default_options
  [:'1. Skip', :'2. Abort', :'3. Create'].sort
end

#retag(entries) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/moneymanager/tagger.rb', line 6

def retag(entries)
  archiver = Moneymanager::Archiver.new

  prompt = TTY::Prompt.new
  entries.each do |entry|
    Layout.clear
    Layout.print_single(entry)
    options = default_options.concat(archiver.tags.sort!)
    action = prompt.select('Do you want add a tags?', options, per_page: 30)

    if action == default_options[0]
      # NOP
    elsif action == default_options[1]
      exit
    elsif action == default_options[2]
      tag = prompt.ask('Create a new tag') do |q|
        q.required true
        q.validate(/^\S*$/)
        q.modify :capitalize
      end
      entry.tag = tag
      archiver.store_tag(tag)
    else
      entry.tag = action
    end
    archiver.update(entry)
  end
end