Class: Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_sys/cli/accounts.rb

Class Method Summary collapse

Class Method Details

.chooser(danarchysys_config) ⇒ Object



3
4
5
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
# File 'lib/danarchy_sys/cli/accounts.rb', line 3

def self.chooser(danarchysys_config)
  accounts = Helpers.array_to_numhash(danarchysys_config[:accounts].keys)
   = 'nil'

  if accounts.count == 1
     = accounts[1]
    return 
  end      

  fields = PrintFormats.printf_hash(accounts)
  printf("#{fields}\n", 'Id', 'Account')
  accounts.each do |id, |
    printf("#{fields}\n", "#{id}.", )
  end

  until accounts.values.include?()
    print 'Which account should we use? (enter \'exit\' to leave): '
     = gets
     =  ? .chomp : abort('Exiting!')

    if  =~ /^[0-9]*$/
       = accounts[.to_i]
    else
       = .to_sym
    end
  end

  
end