reportinator 0.1.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -7
- data/Gemfile.lock +11 -1
- data/README.md +201 -291
- data/app/reports/example.report.json +7 -3
- data/app/reports/multiplication.report.json +1 -1
- data/app/reports/multiplication_v2.report.json +15 -0
- data/data/schema/report_schema.json +76 -0
- data/docs/0_first_report.md +267 -0
- data/lib/reportinator/base.rb +2 -1
- data/lib/reportinator/config.rb +30 -0
- data/lib/reportinator/function.rb +33 -0
- data/lib/reportinator/functions/array/flatten.rb +12 -0
- data/lib/reportinator/functions/array/helper.rb +77 -0
- data/lib/reportinator/functions/array/join.rb +11 -0
- data/lib/reportinator/functions/array/method.rb +9 -0
- data/lib/reportinator/functions/array/range.rb +11 -0
- data/lib/reportinator/functions/array/snippet.rb +30 -0
- data/lib/reportinator/functions/array/string.rb +10 -0
- data/lib/reportinator/functions/array.rb +43 -0
- data/lib/reportinator/functions/string/addition.rb +11 -0
- data/lib/reportinator/functions/string/constant.rb +9 -0
- data/lib/reportinator/functions/string/date.rb +9 -0
- data/lib/reportinator/functions/string/join.rb +10 -0
- data/lib/reportinator/functions/string/logical.rb +14 -0
- data/lib/reportinator/functions/string/number.rb +33 -0
- data/lib/reportinator/functions/string/range.rb +14 -0
- data/lib/reportinator/functions/string/symbol.rb +9 -0
- data/lib/reportinator/functions/string/variable.rb +12 -0
- data/lib/reportinator/functions/string.rb +29 -0
- data/lib/reportinator/helpers.rb +29 -0
- data/lib/reportinator/parser.rb +25 -0
- data/lib/reportinator/parsers/method.rb +8 -3
- data/lib/reportinator/parsers/report.rb +47 -0
- data/lib/reportinator/parsers/value.rb +15 -112
- data/lib/reportinator/report/column.rb +25 -0
- data/lib/reportinator/report/loader.rb +71 -0
- data/lib/reportinator/report/report.rb +33 -0
- data/lib/reportinator/report/row.rb +42 -0
- data/lib/reportinator/report/template.rb +108 -0
- data/lib/reportinator/{report.rb → report_type.rb} +4 -1
- data/lib/reportinator/types/model.rb +15 -7
- data/lib/reportinator/types/preset.rb +23 -2
- data/lib/reportinator/version.rb +1 -1
- data/lib/reportinator.rb +23 -9
- metadata +48 -5
- data/lib/reportinator/loader.rb +0 -112
data/README.md
CHANGED
@@ -18,334 +18,179 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
18
18
|
$ gem install reportinator
|
19
19
|
|
20
20
|
## Usage
|
21
|
-
|
22
|
-
|
23
|
-
Say we want a multiplication table, like such:
|
24
|
-
| nx1 | nx2 | nx3 | nx4 | nx5 |
|
25
|
-
|-----|-----|-----|-----|-----|
|
26
|
-
| 1 | 2 | 3 | 4 | 5 |
|
27
|
-
| 2 | 4 | 6 | 8 | 10 |
|
28
|
-
| 3 | 6 | 9 | 12 | 15 |
|
29
|
-
| 4 | 8 | 12 | 16 | 20 |
|
30
|
-
| 5 | 10 | 15 | 20 | 25 |
|
31
|
-
|
32
|
-
Make a new file in your `app/reports` directory.
|
33
|
-
Name it `multiplication.report.json`
|
34
|
-
|
35
|
-
Set it's type to ":preset". The ":preset" type takes one parameter, "data",
|
36
|
-
and returns any values passed inside it, but with their values parsed.
|
37
|
-
We put a colon in front of the word "preset", such that the value parser
|
38
|
-
knows to turn it into a symbol.
|
21
|
+
For a detailed walkthrough of creating your first report, see
|
22
|
+
[Creating my First Report](docs/0_first_report.md)
|
39
23
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
```
|
45
|
-
|
46
|
-
Next we need to give it parameters to be passed into the report.
|
47
|
-
":preset" only accepts the "data" parameter.
|
48
|
-
Add "data" to a "params" object, and set it to be an empty array.
|
24
|
+
### Where to put my Reports?
|
25
|
+
By default, Reportinator checks `app/reports` for reports.
|
26
|
+
It checks for files named `*.json` and `*.report.json`
|
27
|
+
More locations and suffixes can be added in the config.
|
49
28
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
"data": []
|
55
|
-
}
|
56
|
-
}
|
57
|
-
```
|
29
|
+
### Getting your Report's Output
|
30
|
+
`Reportinator.report(template, params)` will output a two dimensional array.
|
31
|
+
If you picture this as a table, each sub array is a row.
|
32
|
+
`params` is optional.
|
58
33
|
|
59
|
-
|
34
|
+
`Reportinator.output(template, params, filename)` will output the report to a csv,
|
35
|
+
in the configured output directory.
|
36
|
+
`params` and `filename` are optional.
|
60
37
|
|
61
|
-
|
62
|
-
|
63
|
-
=>
|
64
|
-
|
38
|
+
Template is the name of the template file, minus the ".json" suffix.
|
39
|
+
Here is how templates are resolved:
|
40
|
+
- "profit" => "app/reports/profit.json"
|
41
|
+
- "users/joined" => "app/reports/users/joined.json"
|
65
42
|
|
66
|
-
|
67
|
-
|
43
|
+
Params is a hash, accepting the same keys as a template would.
|
44
|
+
Params are merged with those provided by the template, overriding any conflicts.
|
68
45
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
"params": {
|
73
|
-
"data": ["nx1","nx2","nx3","nx4","nx5"]
|
74
|
-
}
|
75
|
-
}
|
76
|
-
```
|
77
|
-
```
|
78
|
-
> Reportinator.report("multiplication")
|
79
|
-
=> [["nx1", "nx2", "nx3", "nx4", "nx5"]]
|
80
|
-
```
|
46
|
+
### Reports in more detail
|
47
|
+
#### The Report Template Object
|
48
|
+
A Report template has four attributes:
|
81
49
|
|
82
|
-
|
50
|
+
| key | type | description |
|
51
|
+
|-----------|--------|----------------------------------------------------|
|
52
|
+
| type | symbol | specifies the report type to use |
|
53
|
+
| template | string | references another template to load and merge with |
|
54
|
+
| metadata | hash | values accessible to parser functions |
|
55
|
+
| params | hash | report specific parameters |
|
83
56
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
"params": {
|
88
|
-
"data": [
|
89
|
-
["nx1","nx2","nx3","nx4","nx5"],
|
90
|
-
[1, 2, 3, 4, 5],
|
91
|
-
[2, 4, 6, 8, 10],
|
92
|
-
[3, 6, 9, 12, 15],
|
93
|
-
[4, 8, 12, 16, 20],
|
94
|
-
[5, 10, 15, 20, 25]
|
95
|
-
]
|
96
|
-
}
|
97
|
-
}
|
98
|
-
```
|
99
|
-
```
|
100
|
-
> Reportinator.report("multiplication")
|
101
|
-
=>
|
102
|
-
[
|
103
|
-
["nx1", "nx2", "nx3", "nx4", "nx5"],
|
104
|
-
[1, 2, 3, 4, 5],
|
105
|
-
[2, 4, 6, 8, 10],
|
106
|
-
[3, 6, 9, 12, 15],
|
107
|
-
[4, 8, 12, 16, 20],
|
108
|
-
[5, 10, 15, 20, 25]
|
109
|
-
]
|
110
|
-
```
|
57
|
+
Values in report templates are passed through the value parser.
|
58
|
+
There are two main types of functions that can be parsed. String functions, and
|
59
|
+
array functions.
|
111
60
|
|
112
|
-
|
113
|
-
|
114
|
-
This allows us to string reports together in the same template.
|
61
|
+
String functions return a value based on the contents of a string input.
|
62
|
+
They are useful for quick conversions, and simple functions.
|
115
63
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
"params": {
|
121
|
-
"data": ["nx1","nx2","nx3","nx4","nx5"]
|
122
|
-
}
|
123
|
-
}
|
124
|
-
]
|
125
|
-
```
|
64
|
+
Array functions return a value based on the contents of an array.
|
65
|
+
They are used for more complex functions, as more can be expressed with them.
|
66
|
+
The values in an array function are usually also parsed, although it is at the discretion
|
67
|
+
of the function do so.
|
126
68
|
|
127
|
-
|
128
|
-
|
69
|
+
#### String Function Cheatsheet
|
70
|
+
| prefix | example | output |
|
71
|
+
|---------|-----------------------------|--------------------------------------------|
|
72
|
+
| `:` | ":symbol" | :symbol |
|
73
|
+
| `&` | "&Constant" | Constant |
|
74
|
+
| `$` | "$variable" | Value `variable` in variables metadata. |
|
75
|
+
| `!a` | "!a 1,2,3" | 6 |
|
76
|
+
| `!d` | "!d 1970-01-01" | 1970-01-01 00:00:00 |
|
77
|
+
| `!n` | "!n 100" | 100 |
|
78
|
+
| `!ni` | "!ni 103.34" | 103 |
|
79
|
+
| `!nf` | "!nf 103" | 103.0 |
|
80
|
+
| `!j` | "!j 1,2,3" | "123" |
|
81
|
+
| `!r` | "!r a,z" | ("a".."z") |
|
82
|
+
| `!rd` | "!rd 1970-01-01,1979-01-01" | (1970-01-01 00:00:00..1979-01-01 00:00:00) |
|
83
|
+
| `!rn` | "!rn 1,100" | (1..100) |
|
84
|
+
| `@true` | "@true" | true |
|
85
|
+
| `@false`| "@false" | false |
|
86
|
+
| `@nil` | "@nil" | nil |
|
87
|
+
| `@null` | "@null" | nil |
|
129
88
|
|
130
|
-
|
131
|
-
|
132
|
-
|
89
|
+
#### Array Function Cheatsheet
|
90
|
+
When an array has a string as it's first value, and that string has a certain prefix,
|
91
|
+
the given array is parsed as an Array Function.
|
133
92
|
|
134
|
-
|
135
|
-
|
93
|
+
Array functions have a target, then an array of values. Often, the values will work
|
94
|
+
with the target to achieve an outcome.
|
136
95
|
|
96
|
+
Take for example this array:
|
137
97
|
```
|
138
|
-
[
|
139
|
-
{
|
140
|
-
"type": ":preset",
|
141
|
-
"params": {
|
142
|
-
"data": ["nx1","nx2","nx3","nx4","nx5"]
|
143
|
-
}
|
144
|
-
},
|
145
|
-
{
|
146
|
-
"type": ":model",
|
147
|
-
"params": {
|
148
|
-
"target": [],
|
149
|
-
"method_list": []
|
150
|
-
}
|
151
|
-
}
|
152
|
-
]
|
98
|
+
["#&Date", ":today", ":to_s"]
|
153
99
|
```
|
100
|
+
This array has the following
|
101
|
+
- a prefix: `#`
|
102
|
+
- a target: `&Date` (Date)
|
103
|
+
- values: `[":today", ":to_s"]` ([:today, :to_s])
|
154
104
|
|
155
|
-
|
156
|
-
|
105
|
+
The `#` prefix tells the parser to run it as a Method Array.
|
106
|
+
The target, `&Date`, is parsed, then the values `[":today", ":to_s"]`
|
107
|
+
are parsed, and sent as methods to it. The result is returned.
|
157
108
|
|
158
|
-
|
159
|
-
each enumeration adding a new row to the report.
|
160
|
-
|
161
|
-
A method is specified by either a symbol, array or hash.
|
162
|
-
Lets take the string "100" as our target.
|
163
|
-
|
164
|
-
If our method was to be `":reverse"`, it would be the same as running"
|
109
|
+
This array is equivalent to running `Date.today.to_s`.
|
165
110
|
|
111
|
+
Optionally, the prefix can be put on it's own, with no additional values
|
112
|
+
after it. The second value, in this case "&Date", will become the target
|
113
|
+
instead.
|
166
114
|
```
|
167
|
-
|
168
|
-
=> "001"
|
115
|
+
["#", "&Date", ":today", ":to_s"]
|
169
116
|
```
|
170
|
-
|
171
|
-
|
172
|
-
|
117
|
+
This will still return the same result. Note that this allows the target
|
118
|
+
to be more flexible, as it no longer has to be resolved from a string.
|
173
119
|
```
|
174
|
-
|
175
|
-
=> 1
|
120
|
+
["#", ["#&Date", ":today"], ":to_s"]
|
176
121
|
```
|
122
|
+
This array is equally valid, and still returns the same result.
|
177
123
|
|
178
|
-
|
179
|
-
|
180
|
-
|
124
|
+
| prefix | example | ruby equivalent |
|
125
|
+
|-----------|------------------------------------------------|-----------------------------------------|
|
126
|
+
| `#` | `["#&Date", ":today"]` | Date.today |
|
127
|
+
| `>join` | `[">join", " - ", "a", "b", "c"]` | ["a", "b", "c"].join(" - ") |
|
128
|
+
| `>strf` | `[">strf", ["#&Date", ":today"], "%b, %Y"]` | Date.today.strftime("%b, %Y") |
|
129
|
+
| `>offset` | `[">offset $time", 2, ":month", ":end"]` | $time.advance(month: 2).at_end_of_month |
|
130
|
+
| `>title` | `[">title", "hello", "world"]` | ["hello", "world"].join(" ").titleize |
|
131
|
+
| `>snippet`| `[">snippet :test", {"var1": "hi"}]` | *See snippets section* |
|
181
132
|
|
182
|
-
Eg. `{"gsub": ["0", "1"]}`
|
183
133
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
134
|
+
### Metadata
|
135
|
+
Metadata is defined in the "metadata" field of the template, and can be used by Parser Functions.
|
136
|
+
Metadata is merged from parent to child report template. Child metadata takes precedence over parent.
|
137
|
+
|
138
|
+
Reportinator's built in Parser Functions use two metadata fields; "variables", and "snippets".
|
188
139
|
|
189
|
-
|
190
|
-
|
140
|
+
#### Variables
|
141
|
+
Variables are values that can be accessed with the "$" string function.
|
191
142
|
|
192
143
|
```
|
193
|
-
|
194
|
-
{
|
195
|
-
"
|
196
|
-
"params": {
|
197
|
-
"data": ["nx1","nx2","nx3","nx4","nx5"]
|
198
|
-
}
|
199
|
-
},
|
200
|
-
{
|
201
|
-
"type": ":model",
|
202
|
-
"params": {
|
203
|
-
"target": [1, 2, 3, 4, 5],
|
204
|
-
"method_list": [{"*": 1},{"*": 2},{"*": 3},{"*": 4},{"*": 5}]
|
205
|
-
}
|
144
|
+
"metadata": {
|
145
|
+
"variables": {
|
146
|
+
"key": "value"
|
206
147
|
}
|
207
|
-
|
148
|
+
}
|
208
149
|
```
|
209
|
-
|
210
|
-
The "*" is behaving exactly the same way as our "gsub" example earlier.
|
211
|
-
|
212
|
-
If we run our report again:
|
213
|
-
|
214
150
|
```
|
215
|
-
> Reportinator.
|
216
|
-
=>
|
217
|
-
[
|
218
|
-
["nx1", "nx2", "nx3", "nx4", "nx5"],
|
219
|
-
[1, 2, 3, 4, 5],
|
220
|
-
[2, 4, 6, 8, 10],
|
221
|
-
[3, 6, 9, 12, 15],
|
222
|
-
[4, 8, 12, 16, 20],
|
223
|
-
[5, 10, 15, 20, 25]
|
224
|
-
]
|
151
|
+
> Reportinator.parse "$key"
|
152
|
+
=> "value"
|
225
153
|
```
|
226
154
|
|
227
|
-
|
228
|
-
|
229
|
-
This is pretty good, but we can do better!
|
230
|
-
Notice how the "target" was an array? As it is enumerable,
|
231
|
-
we could run our methods against each element within it.
|
232
|
-
|
233
|
-
But what if we wanted to have 10 rows? Or 50? Soon our array is going to get pretty long.
|
234
|
-
|
235
|
-
This is where a range would be perfect. Set the start value to 1, the end to whatever number we need,
|
236
|
-
and then we go from there.
|
237
|
-
|
238
|
-
Unfortunately, we can't use a range in JSON.
|
239
|
-
|
240
|
-
... or can we?
|
241
|
-
|
242
|
-
Reportinator has a bunch of handy built in functions, for converting strings.
|
243
|
-
We have already seen ":symbol" to make a string into a symbol.
|
244
|
-
|
245
|
-
We won't explore all the functions now, but we will explore "!r".
|
246
|
-
Or more specifically, "!rn", which auto converts strings into numbers as well.
|
247
|
-
|
248
|
-
We can make a range simply by writing "!rn 1,5". It takes the number before the comma,
|
249
|
-
as the start of the range, and the one after as the end.
|
250
|
-
|
251
|
-
We can test this with the actual parse method:
|
155
|
+
Variable values are also parsed, and themselves can even reference variables from parent templates.
|
252
156
|
|
253
157
|
```
|
254
|
-
|
255
|
-
|
158
|
+
# $date = 1970-01-01
|
159
|
+
"metadata": {
|
160
|
+
"variables": {
|
161
|
+
"formatted_date": [">strf", "$date", "%b %d, %Y"]
|
162
|
+
}
|
163
|
+
}
|
164
|
+
```
|
165
|
+
```
|
166
|
+
> Reportinator.parse "$formatted_date"
|
167
|
+
=> "Jan 01, 1970"
|
256
168
|
```
|
257
169
|
|
258
|
-
|
170
|
+
#### Snippets
|
171
|
+
Snippets are values that are not parsed until called from the ">snippet" array function,
|
172
|
+
as opposed to variables, which are parsed before they are able to be called.
|
259
173
|
|
174
|
+
Snippets can be passed variables with a hash in the first value of the array function.
|
175
|
+
|
176
|
+
Example:
|
260
177
|
```
|
261
|
-
|
262
|
-
{
|
263
|
-
"
|
264
|
-
"params": {
|
265
|
-
"data": ["nx1","nx2","nx3","nx4","nx5"]
|
266
|
-
}
|
267
|
-
},
|
268
|
-
{
|
269
|
-
"type": ":model",
|
270
|
-
"params": {
|
271
|
-
"target": "!rn 1,5",
|
272
|
-
"method_list": [{"*": 1},{"*": 2},{"*": 3},{"*": 4},{"*": 5}]
|
273
|
-
}
|
178
|
+
"metadata": {
|
179
|
+
"snippets": {
|
180
|
+
"plus_10": [">sum", "$var", 10]
|
274
181
|
}
|
275
|
-
|
182
|
+
}
|
276
183
|
```
|
277
|
-
|
278
|
-
Finally, rather than peering at the console to see if it worked,
|
279
|
-
lets put it into a csv.
|
280
|
-
|
281
184
|
```
|
282
|
-
> Reportinator.
|
283
|
-
=>
|
185
|
+
> Reportinator.parse [">snippet :plus_10", { "var": 5 }]
|
186
|
+
=> 15
|
284
187
|
```
|
285
188
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
| key | type | description |
|
293
|
-
|-----------|--------|----------------------------------------------------|
|
294
|
-
| type | symbol | specifies the report type to use |
|
295
|
-
| variables | hash | defines variables to be used with the `$` function |
|
296
|
-
| template | string | references another template to load and merge with |
|
297
|
-
| params | hash | report specific parameters |
|
298
|
-
|
299
|
-
#### Reportinator String Parse Cheatsheet
|
300
|
-
| prefix | example | output |
|
301
|
-
|--------|-----------------------------|--------------------------------------------|
|
302
|
-
| `:` | ":symbol" | :symbol |
|
303
|
-
| `&` | "&Constant" | Constant |
|
304
|
-
| `$` | "$variable" | Value of key `variable` in variables hash. |
|
305
|
-
| `!a` | "!a 1,2,3" | 6 |
|
306
|
-
| `!d` | "!d 1970-01-01" | 1970-01-01 00:00:00 |
|
307
|
-
| `!n` | "!n 100" | 100 |
|
308
|
-
| `!r` | "!r a,z" | ("a".."z") |
|
309
|
-
| `!rd` | "!rd 1970-01-01,1979-01-01" | (1970-01-01 00:00:00..1979-01-01 00:00:00) |
|
310
|
-
| `!rn` | "!rn 1,100" | (1..100) |
|
311
|
-
|
312
|
-
#### Reportinator Method Parse Cheatsheet
|
313
|
-
When an array has a string as it's first value, and that string has the `#` prefix,
|
314
|
-
that string is parsed, and the result becomes the target of the following methods.
|
315
|
-
|
316
|
-
Hashes within the array take the first key in the hash as the method,
|
317
|
-
and the first value as parameters for that method. If the first value
|
318
|
-
is an array, each item in the array is sent as a seperate parameter.
|
319
|
-
|
320
|
-
Subsequent symbols in the array are sent as methods to the target.
|
321
|
-
| method array | ruby equivalent |
|
322
|
-
|------------------------------------------------|-------------------------------|
|
323
|
-
| `["#&Date", ":today"]` | Date.today |
|
324
|
-
| `["#&Date", ":today", ":to_s"]` | Date.today.to_s |
|
325
|
-
| `["#&Date", ":today", {"strftime": "%b, %Y"}]` | Date.today.strftime("%b, %Y") |
|
326
|
-
| `["#&Range", {"new": [1,100]}]` | Range.new(1, 100) |
|
327
|
-
|
328
|
-
### Where to put my Reports?
|
329
|
-
By default, Reportinator checks `app/reports` for reports.
|
330
|
-
It checks for files named `*.json` and `*.report.json`
|
331
|
-
More locations and suffixes can be added in the config.
|
332
|
-
|
333
|
-
### Getting your Report's Output
|
334
|
-
`Reportinator.report(template, params)` will output a two dimensional array.
|
335
|
-
If you picture this as a table, each sub array is a row.
|
336
|
-
`params` is optional.
|
337
|
-
|
338
|
-
`Reportinator.output(template, params, filename)` will output the report to a csv,
|
339
|
-
in the configured output directory.
|
340
|
-
`params` and `filename` are optional.
|
341
|
-
|
342
|
-
Template is the name of the template file, minus the ".json" suffix.
|
343
|
-
Here is how templates are resolved:
|
344
|
-
- "profit" => "app/reports/profit.json"
|
345
|
-
- "users/joined" => "app/reports/users/joined.json"
|
346
|
-
|
347
|
-
Params is a hash, accepting the same keys as a template would.
|
348
|
-
Params are merged with those provided by the template, overriding any conflicts.
|
189
|
+
Snippets help to reduce repetition of complex functionality in a report.
|
190
|
+
However, if a report is getting unwieldy with complex values to parse, it might
|
191
|
+
be a good idea to write a Custom Parser Function, or to write it into a method
|
192
|
+
on a class, and call it from a "&Constant". See the next section for setting up
|
193
|
+
custom functions.
|
349
194
|
|
350
195
|
### Configuring Reportinator
|
351
196
|
```
|
@@ -356,6 +201,9 @@ Reportinator.configuration do |config|
|
|
356
201
|
config.report_types = {
|
357
202
|
my_type: "MyModule::MyReportType"
|
358
203
|
}
|
204
|
+
config.parser_functions = [
|
205
|
+
"MyModule::MyParserFunction"
|
206
|
+
]
|
359
207
|
end
|
360
208
|
```
|
361
209
|
Configuration set will not override the default configuration.
|
@@ -365,19 +213,81 @@ of the reports.
|
|
365
213
|
### Making a Custom Report Type
|
366
214
|
The requirements to make a Report are very simple.
|
367
215
|
1. The report must inherit from `Reportinator::Report`
|
368
|
-
2. The report
|
216
|
+
2. The report should provide some attributes, to be set with the "params" field,
|
217
|
+
3. The report must provide a `data` method, which returns either a Reportinator::Row,
|
218
|
+
or an array of them.
|
369
219
|
|
370
|
-
|
220
|
+
Here's an example of a basic report type:
|
371
221
|
```
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
222
|
+
class BasicReport < Reportinator::Report
|
223
|
+
attribute :values, default: []
|
224
|
+
|
225
|
+
def data
|
226
|
+
Reportinator::Row.create(values)
|
227
|
+
end
|
376
228
|
end
|
377
229
|
```
|
230
|
+
|
231
|
+
`Reportinator::Row.create` takes in an array, and turns it into a Row.
|
232
|
+
For more fine-grained control, an instance of a Row can have data
|
233
|
+
inserted into it with the `insert` method. `insert` takes any data, then
|
234
|
+
a position, being either :first, :last, or an index number, to indicate where in
|
235
|
+
the row the data should be inserted.
|
236
|
+
|
378
237
|
Once a report has been written, it must be registed as a report type.
|
379
238
|
See the configuration section for more details.
|
380
239
|
|
240
|
+
### Making a Custom Parser Function
|
241
|
+
The requirements to make a Parser Function are fairly simple:
|
242
|
+
1. The function must inherit from either "Reportinator::StringFunction"
|
243
|
+
or "Reportinator::ArrayFunction"
|
244
|
+
2. The function must have a PREFIXES constant, with an array of the prefixes it'll accept.
|
245
|
+
3. The function must provide an `output` method
|
246
|
+
|
247
|
+
All functions have access to the `metadata` variable.
|
248
|
+
|
249
|
+
String functions gain access to two additional variables:
|
250
|
+
- `prefix`, the prefix that the string used
|
251
|
+
- `body`, the rest of the string with the prefix removed
|
252
|
+
|
253
|
+
Array functions gain access to three additional variables:
|
254
|
+
- `prefix`, the prefix that was used
|
255
|
+
- `target`, the first value after the prefix
|
256
|
+
- `values`, the rest of the values, with the target removed
|
257
|
+
|
258
|
+
Once a function has been written, it must be registed as a parser function.
|
259
|
+
See the configuration section for more details.
|
260
|
+
|
261
|
+
#### Example String Function:
|
262
|
+
```
|
263
|
+
class TitleizeStringFunction < Reportinator::StringFunction
|
264
|
+
PREFIXES = ["!t"]
|
265
|
+
|
266
|
+
def output
|
267
|
+
body.titleize
|
268
|
+
end
|
269
|
+
end
|
270
|
+
```
|
271
|
+
```
|
272
|
+
> Reportinator.parse "!t hello world"
|
273
|
+
=> "Hello World"
|
274
|
+
```
|
275
|
+
|
276
|
+
#### Example Array Function:
|
277
|
+
```
|
278
|
+
class TargetSumArrayFunction < Reportinator::ArrayFunction
|
279
|
+
PREFIXES = [">targetsum"]
|
280
|
+
|
281
|
+
def output
|
282
|
+
values.map { |value| value + target }
|
283
|
+
end
|
284
|
+
end
|
285
|
+
```
|
286
|
+
```
|
287
|
+
> Reportinator.parse [">targetsum", 10, 1, 2, 3]
|
288
|
+
=> [11, 12, 13]
|
289
|
+
```
|
290
|
+
|
381
291
|
## Development
|
382
292
|
|
383
293
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -386,7 +296,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
386
296
|
|
387
297
|
## Contributing
|
388
298
|
|
389
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
299
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/moxvallix/reportinator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/moxvallix/reportinator/blob/master/CODE_OF_CONDUCT.md).
|
390
300
|
|
391
301
|
## License
|
392
302
|
|
@@ -394,4 +304,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
394
304
|
|
395
305
|
## Code of Conduct
|
396
306
|
|
397
|
-
Everyone interacting in the Reportinator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
307
|
+
Everyone interacting in the Reportinator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/moxvallix/reportinator/blob/master/CODE_OF_CONDUCT.md).
|
@@ -1,9 +1,13 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
3
|
"type": ":preset",
|
4
|
-
"
|
4
|
+
"metadata": {
|
5
|
+
"variables": {
|
6
|
+
"variable": "i am a variable"
|
7
|
+
}
|
8
|
+
},
|
5
9
|
"params": {
|
6
|
-
"
|
10
|
+
"values": [
|
7
11
|
"string", ":symbol", "&Reportinator",
|
8
12
|
"$variable", "!i 1234", "!a !i 2, 2",
|
9
13
|
["#!d 1970-01-01", {"strftime": "%b, %Y"}], "!r !i 1, !i 5"
|
@@ -13,7 +17,7 @@
|
|
13
17
|
{
|
14
18
|
"type": ":model",
|
15
19
|
"params": {
|
16
|
-
"target": ["
|
20
|
+
"target": ["#", "&Reportinator", ":config"],
|
17
21
|
"method_list": [":configured_directories", ":configured_suffixes", ":configured_types"]
|
18
22
|
}
|
19
23
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"type": ":preset",
|
4
|
+
"params": {
|
5
|
+
"values": ["5x5","nx1","nx2","nx3","nx4","nx5"]
|
6
|
+
}
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"type": ":model",
|
10
|
+
"params": {
|
11
|
+
"target": "!rn 1,5",
|
12
|
+
"method_list": [[">join", "x", "$target", "n"],{"*": 1},{"*": 2},{"*": 3},{"*": 4},{"*": 5}]
|
13
|
+
}
|
14
|
+
}
|
15
|
+
]
|