-
Notifications
You must be signed in to change notification settings - Fork 0
/
comptes
executable file
·65 lines (51 loc) · 1.25 KB
/
comptes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/ruby
# -*- encoding : utf-8 -*-
require 'yaml'
require "docopt"
require 'pp'
require_relative 'oo_reader'
require_relative 'txt_reader'
require_relative 'comptes'
require_relative 'depenses'
doc = <<DOCOPT
Usage: #{__FILE__} <input_file> [-c <config_file>]
Options:
-c --config Config file to use
Input file can be OpenOffice Spreadsheet file (.ods), or text file (.txt).
See examples for more about format.
DOCOPT
begin
docopt = Docopt::docopt(doc)
rescue Docopt::Exit => e
puts e.message
exit 1
end
# Test file existence
input_file = docopt['<input_file>']
unless File.exists?(input_file)
puts "#{input_file} doesn't exists"
exit 1
end
# Open config
config_file = docopt['--config'] ? docopt['<config_file>'] : 'config.yml'
conf = YAML.load_file(config_file)
# Solving
if input_file.end_with?('.ods')
o = OoReader.new(input_file, conf)
elsif input_file.end_with?('.txt')
o = TxtReader.new(input_file, conf)
else
puts "#{input_file}: unknown file extension. Must be '.txt' or '.ods'."
exit 2
end
Comptes.affichage_probleme(o)
resultat = Comptes.calcul_dettes(o, conf['transfers_priorities_order'])
puts
puts
puts "Résultat :"
puts
puts resultat
puts
puts
puts "Vérification :"
Comptes.affichage_verification_resultat(o, resultat)