22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/cc_manager/cli.rb', line 22
def process
file = options['file']
@accounts, @errors = [], []
counter = 1
if File.exist?(file)
File.open(file, "r") do |infile|
while (line = infile.gets)
args = line.split(" ")
action = args.first.downcase
case(action)
when "add" add(args, line, counter)
when "charge", "credit" update(action, args, line, counter)
else
add_errors(counter, line, "Invalid Action Specified!!!")
end
counter = counter + 1
end
end
else
say("Invalid File location. Please Enter Valid path of File!!!", :red)
end
say("\n\nOUTPUT: \n\n", :yellow)
@accounts.sort! { |a,b| a.name <=> b.name }
@accounts.each do |a|
if a.valid?
say("#{a.name}: #{a.balance}", :green)
else
say("#{a.name}: Error", :red)
end
end
if options['errors']
display_errors
end
end
|