ci: do not error when nothing with nitunit_some
[nit.git] / contrib / refund / src / refund.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2015 Alexandre Terrasa <alexandre@moz-code.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Insurance refunds calculation tool.
18 #
19 # `refund` computes automatically the allowed refund for a reclamation according
20 # to an insurrance policy.
21 #
22 # Usage:
23 #
24 # ~~~sh
25 # > refund (<input_file> <output_file> | [OPTIONS])
26 # ~~~
27 #
28 # Input file:
29 #
30 # `refund` expects a JSON input file on the form:
31 #
32 # ~~~json
33 # {
34 # "dossier": "A100323",
35 # "mois": "2015-01",
36 # "reclamations": [
37 # {
38 # "soin": 100,
39 # "date": "2015-01-11",
40 # "montant": "234.00$"
41 # }, {
42 # "soin": 200,
43 # "date": "2015-01-13",
44 # "montant": "128.00$"
45 # }, {
46 # "soin": 334,
47 # "date": "2015-01-23",
48 # "montant": "50.00$"
49 # }
50 # ]
51 # }
52 # ~~~
53 #
54 # Output file:
55 #
56 # You have to specify the path where `refund` should output the result file.
57 #
58 # Results are formatted as JSON:
59 #
60 # ~~~json
61 # {
62 # "client": "100323",
63 # "mois": "2015-01",
64 # "remboursements": [
65 # {
66 # "soin": 100,
67 # "date": "2015-01-11",
68 # "montant": "58.50$"
69 # }, {
70 # "soin": 200,
71 # "date": "2015-01-13",
72 # "montant": "22.50$"
73 # }, {
74 # "soin": 334,
75 # "date": "2015-01-23",
76 # "montant": "0.00$"
77 # }
78 # ]
79 # }
80 # ~~~
81 #
82 # Options:
83 #
84 # `refund` can generate statistics about reclamations and refunds computed.
85 #
86 # * `-S`: display statistics
87 # * `-SR`: reset statistics
88 #
89 # Error handling:
90 #
91 # In case of error, a JSON object is generated in place of the output file:
92 #
93 # ~~~json
94 # { "message": "Invalid input data" }
95 # ~~~
96 module refund
97
98
99 import refund_json
100
101 # Display usage in console then leave.
102 fun usage do
103 print ""
104 print "Usage:"
105 print "refund <input.json> <output.json>"
106 print ""
107 print "options"
108 print " -S\tShow stats in console"
109 print " -RS\tClear stats"
110 exit 1
111 end
112
113 var proc = new RefundProcessor
114
115 if args.length == 1 then
116 var flag = args.first
117 if flag == "-RS" then
118 proc.clear_stats
119 exit 0
120 else if flag == "-S" then
121 proc.show_stats
122 exit 0
123 else
124 print "Error: Unknown flag {flag}."
125 usage
126 end
127 else if args.length != 2 then
128 print "Error: Incorrect number of arguments. Got {args.length}, expected 2."
129 usage
130 end
131
132 proc.process(args[0], args[1])