-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rb
More file actions
executable file
·38 lines (29 loc) · 772 Bytes
/
Copy pathcli.rb
File metadata and controls
executable file
·38 lines (29 loc) · 772 Bytes
1
2
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
32
33
34
35
36
37
38
#!/usr/bin/env ruby
require 'json'
require './src/process_invoices'
include ProcessInvoices
if ARGV.length < 2
puts "We need the parameters to the files"
exit
end
def read_file(path)
begin
file = File.open(path)
content = file.read
file.close
hash = JSON.parse(content)
rescue
puts "Failed to open: " + path
exit
end
return hash
end
credit_line = read_file(ARGV[0])
invoices = read_file(ARGV[1])
updated_credit_line , processed_invoices = finance_customer(credit_line, invoices )
puts "\n\n • Financed amount:"
puts "\n " + credit_line['customer'].to_s
puts "\n\n • Invoices processed:"
puts "\n " + JSON.pretty_generate(processed_invoices)
puts "\n\n • Remaining customer credit:"
puts "\n " + updated_credit_line.to_s